StringUtils工具类中的isBlank()方法和isEmpty()方法的区别

1.isBlank()方法

 1 public static boolean isBlank(String str) { 
 2         int strLen;
 3         if (str == null || (strLen = str.length()) == 0) {            //判断str是否为null或者str长度是否等于0
 4             return true;
 5         }
 6         for (int i = 0; i < strLen; i++) {
 7             if ((Character.isWhitespace(str.charAt(i)) == false)) {  //空白字符的判断
 8                 return false;
 9             }
10         }
11         return true;
12     }

2.isEmpty()方法

1 public static boolean isEmpty(String str) {
2         return str == null || str.length() == 0;         //判断str的是否是null或者str长度是否等于0
3     }

可以看出isBlank()方法和isEmpty()最大的区别就是对字符串中是否有空白字符的判断

public static void main(String[] args) {
        System.out.println(StringUtils.isBlank("  "));    //true
System.out.println(StringUtils.isEmpty(" "));    //flase
    }
原文地址:https://www.cnblogs.com/coder-wf/p/12127757.html