StringUtils

StringUtils位置:org.apache.commons.lang3.StringUtils

isEmpty和isBlank还是有些区别的:

isEmpty源码:

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

isBlank源码:

/**
 * <p>Checks if a CharSequence is whitespace, empty ("") or null.</p>
 * @param cs  the CharSequence to check, may be null
 * @return {@code true} if the CharSequence is null, empty or whitespace
 * @since 2.0
 * @since 3.0 Changed signature from isBlank(String) to isBlank(CharSequence)
 */
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;
}
空串:即不包含任何元素的字符串,表示为""
空格:即"  ",对应ascii码是32
空白字符:是一组非可见的字符,对于文本处理来说,除了空格外,通常包括tab(\t)、回车(\r)、换行(\n)、垂直制表符(\v)、换页符(\f),windows系统常用的回车换行的组合(\r\n)也算在其中
总结就是:isBlank是严格意义上的判空操作,而isEmpty无法判断出来空格,例如:"  "

  

 

更加详细的说明可以参照: https://www.cnblogs.com/sealy321/p/10227131.html

官方API文档:https://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/StringUtils.html

 

posted @ 2021-10-13 10:01  宥晔  阅读(48)  评论(0编辑  收藏  举报