isEmpty isBlank 区别

Sring test=“  “; 这个 isblank 返回 true 但是 isEmpty 返回 false
 
所以: 一般用 isBlank 就可以了 ,是逐个字符检查
public static boolean isBlank(String str) {
int strLen;
if(str != null && (strLen = str.length()) != 0) {
for(int i = 0; i < strLen; ++i) {
if(!Character.isWhitespace(str.charAt(i))) {
return false;
}
}

return true;
} else {
return true;
}
}

public static boolean isEmpty(String str) {
return str == null || str.length() == 0;
}
posted @ 2017-06-15 17:16  義丨往昔灬miller  阅读(195)  评论(0编辑  收藏  举报