StringUtils工具类中的isNotBlank()方法和isNotEmpty()方法的区别

1.isNotBlank()方法

 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.isNotEmpty()方法

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

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

public static void main(String[] args) {
        System.out.println(StringUtils.isNotEmpty("  "));    //true
System.out.println(StringUtils.isNotBlank(
" "));   //false }

 

posted @ 2019-07-04 13:41  霍宇飞  阅读(10268)  评论(0编辑  收藏  举报