StringUtils总isBlank和isEmpty的区别

StringUtils中isBlank和isEmpty的区别

isEmpty源码

Checks if a CharSequence is empty (“”) or null.

public static boolean isEmpty(final CharSequence cs) {
        return cs == null || cs.length() == 0;
    }

isBlank

Checks if a CharSequence is whitespace, empty (“”) or null.

比isEmpty多了空字符串的校验

 public static boolean isBlank(final CharSequence cs) {
        int strLen;
        if (cs == null || (strLen = cs.length()) == 0) {
            return true;
        }
        for (int i = 0; i < strLen; i++) {
            if (Character.isWhitespace(cs.charAt(i)) == false) {
                return false;
            }
        }
        return true;
    }

猜你喜欢

转载自blog.csdn.net/qq_22027637/article/details/79776763
今日推荐