天天看點

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