原创

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

本文来自:StringUtils 几个判断空值的方法-小码农,转载请保留本条链接,感谢!

温馨提示:
本文最后更新于 2021年01月26日,已超过 1,185 天没有更新。若文章内的图片失效(无法正常加载),请留言反馈或直接联系我
正文到此结束
该篇文章的评论功能已被站长关闭
本文目录