Checks if the String contains only whitespace in Java
Description
The following code shows how to checks if the String contains only whitespace.
Example
//w w w. jav a2s. c o m
public class Main {
public static boolean isWhitespace(String str) {
if (str == null) {
return false;
}
int sz = str.length();
for (int i = 0; i < sz; i++) {
if ((Character.isWhitespace(str.charAt(i)) == false)) {
return false;
}
}
return true;
}
public static void main(String[] argv){
System.out.println(isWhitespace("java2s.com") );
}
}
The code above generates the following result.
Home »
Java Tutorial »
Java Data Type »
Java Tutorial »
Java Data Type »