1、isBlak()
在校验一个String类型的变量是否为空时,通常存在3中情况
是否为 null,是否为 "",是否为空字符串(引号中间有空格) 如: " "。
StringUtils的isBlank()方法可以一次性校验这三种情况,返回值都是true。
当受检查的值时 null 时,返回true;当受检查值时 ""时,返回值时true;当受检查值是空字符串时,返回值是true。
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;
    }
}
2、 isEmpty(str) 注意:在StringUtils中空格按照非空来处理
判断某字符串是否为空,为空的标准是 str==null 或 str.length()==0
public static boolean isEmpty(String str) {
    return str == null || str.length() == 0;
}
3、 isNotEmpty(String str)
判断某字符串是否非空,等于 !isEmpty(String str)
public static boolean isNotEmpty(String str) {
    return !isEmpty(str);
}
 
                    
                 
 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号