Checks if the String contains only whitespace.
* *null
will return false
.
* An empty String ("") will return true
.
* StringUtils.isWhitespace(null) = false * StringUtils.isWhitespace("") = true * StringUtils.isWhitespace(" ") = true * StringUtils.isWhitespace("abc") = false * StringUtils.isWhitespace("ab2c") = false * StringUtils.isWhitespace("ab-c") = false ** * @param str the String to check, may be null * @return
true
if only contains whitespace, and is non-null
* @since 2.0
*/
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;
}
}