isEmpty和isBlank的区别

isEmpty只判断是否为null和长度是否为0

  public static boolean isEmpty(String str) {
        return str == null || str.length() == 0;
    }

isBlank判断的是该字符串是否为空白字符串

    public static boolean isBlank(String str) {
        int strLen;
        if (str != null && (strLen = str.length()) != 0) {
            for(int i = 0; i < strLen; ++i) {
                if (!Character.isWhitespace(str.charAt(i))) {
                    return false;
                }
            }

            return true;
        } else {
            return true;
        }
    }

 

posted @ 2020-03-22 14:19  踏月而来  阅读(259)  评论(0编辑  收藏  举报