小码农 猫的一生在打哈欠中度过

StringUtils 几个判断空值的方法

org.apache.commons.lang 包下,包含多个判断空或者空字符串的方法,下面看下原形

isEmpty方法原形:

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

isNotEmpty 方法原形

public static boolean isNotEmpty(String str) {
    return ((str != null) && (str.length() > 0));
}

isBlank方法原形

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

isNotBlank方法原形

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

推荐使用isNotEmpty

赏
支付宝赞赏码
支付宝
微信赞赏码
微信
分享 微博 QQ 空间 豆瓣 Twitter

本文最后更新于 2021 年 01 月 26 日,距今日已 2112 天。

本文出自 小码农,转载请注明出处。

此篇已闭评。

卷首