判断charsequence是否为空

1.

  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))) {
                return false;
            }
        }
        return true;
    }

    public static boolean isNotBlank(final CharSequence cs) {
        return !isBlank(cs);
    }

    public static String defaultString(Object obj) {
        return obj == null ? "" : obj.toString();
    }
}
原文地址:https://www.cnblogs.com/bravolove/p/5805518.html