Date: 2013mar2
Update: 2025sep29
Language: Java
Level: novice
Q. Java: Is there an isspace(c) in Java (as in C)?
A. Use Character.isWhitespace() as shown in this full example:
import java.lang.Character;
class Demo {
public static final void main(String []args) {
final String str = "\tone ()";
for (char c : str.toCharArray()) {
boolean b = Character.isWhitespace(c); // HERE
System.out.println("is '" + c + "' space=" + b);
}
}
}
Output:
is ' ' space=true
is 'o' space=false
is 'n' space=false
is 'e' space=false
is ' ' space=true
is '(' space=false
is ')' space=false
If you find yourself looping thru a string in C-style its probably
better to use a Java Pattern match.