isNotEmpty 的源码:
public static boolean isNotEmpty(CharSequence cs){
return (cs != null) && (cs.length() > 0);
}
解析:只有当字符串非空串(" ")并且非空(null)时才返回true
示例:
StringUtils.isNotEmpty("") = flase
StringUtils.isNotEmpty(" ") = true
isNotBlank的源码:
public static boolean isNotBlank(CharSequence cs)
{
int strLen;
if ((cs != null) && ((strLen = cs.length()) > 0))
return true;
int strLen;
for (int i = 0; i < strLen; i++) {
if (!Character.isWhitespace(cs.charAt(i))) {
return true;
}
}
return false;
}
解析:只有当字符串非空串(" ",全是空格、tab键、换行也属于空串)并且非空(null)时才返回true
示例:
StringUtils.isNotEmpty("") = false
StringUtils.isNotEmpty(" ") = false
经验:isNotBlank使用适合场景比较多,频率高。