public boolean isEmpty() {
return value.length == 0;
}
字符串的isEmpty()判断的是值的长度。当字符串是多个空格时,长度是不为0的。返回为false。(除非字符串先trim处理下,再用这个判断。)
如果想一起判断null和非空字符串,建议直接用字符串工具类StringUtils的StringUtils.isBlank()方法
public static boolean isBlank(CharSequence cs) {
int strLen;
if (cs != null && (strLen = cs.length()) != 0) {
for(int i = 0; i < strLen; ++i) {
if (!Character.isWhitespace(cs.charAt(i))) {
return false;
}
}
return true;
} else {
return true;
}
}