if判斷問題
public static void main(String[] args) {
StringBuffer str = new StringBuffer();
int i = 0;
for (int k = 0; k <10; k++) {
str.append( i+",");
i++;
}
if (StringUtils.isNotBlank(str)){
System.out.println("判斷非空");
}
if (StringUtils.isNotEmpty(str)){
System.out.println("判斷非空");
}
if (StringUtils.isBlank(str)){
System.out.println("判斷爲空");
}
}
控制檯打印
判斷非空
判斷非空
Process finished with exit code 0
底層代碼
isNotBlank
public static boolean isNotBlank(CharSequence cs) {
return !isBlank(cs);
}
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;
}
}
isNotEmpty
public static boolean isNotEmpty(CharSequence cs) {
return !isEmpty(cs);
}
public static boolean isEmpty(CharSequence cs) {
return cs == null || cs.length() == 0;
}