org.apache.commons.lang.StringUtils ISBANK方法内部实现
public static boolean isBlank(String str) {
int strLen;
//如果字符串为空或者字符串是空字符串"",返回true
if (str == null || (strLen = str.length()) == 0) {
return true;
}
strLen = str.length();
//如果为空字符,继续判断,如果不为空字符直接ruturn false,说明该字符
串不为空
for (int i = 0; i < strLen; i++) {
if ((Character.isWhitespace(str.charAt(i)) == false))
{
return false;
}
}
return true;
}
Character.isWhitespace()判断字符是否为空白字符
如果是自己写一个这样的功能,我估计想不到用Character.isWhitespace()
本人菜鸟,程序员生涯第一篇博客,今后会越来越深入。