判断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();
    }
}

 

posted @ 2016-08-25 09:33  黑土白云  阅读(1048)  评论(0编辑  收藏  举报