问题:StrUtil.isNotEmpty(str);方法等价于str!=null&&str.length()!=0吗
首先看一下StrUtil.isNotEmpty方法的内部实现
public static boolean isNotEmpty(CharSequence str) {
return !isEmpty(str);
}
public static boolean isEmpty(CharSequence str) {
return str == null || str.length() == 0;
}
解答:是的,StrUtil.isNotEmpty(str);方法等价于str!=null&&str.length()!=0
拓展:
System.out.println(StrUtil.isNotEmpty(""));//false
System.out.println(StrUtil.isNotEmpty(" "));//true
public static boolean isBlank(CharSequence str) {
int length;
if (str != null && (length = str.length()) != 0) {
for(int i = 0; i < length; ++i) {
if (!CharUtil.isBlankChar(str.charAt(i))) {
return false;
}
}
return true;
} else {
return true;
}
}