0
点赞
收藏
分享

微信扫一扫

判断字符串是否为空或者空格

三千筱夜 2022-03-30 阅读 73
javajava-ee
package com.wc.utils;

public class StringUtils {
    /**
     * 判断字符串是否为空
     * @param cs
     * @return
     */
    public static Boolean isEmpty(CharSequence cs) {
        return cs == null || cs.length() == 0;
    }

    /**
     * 判断字符串的是否为空或者空格
     * @param sc
     * @return
     */
    public static Boolean isBlank(CharSequence sc) {
        if (sc != null && sc.length() > 0) {
            for (int i = 0; i < sc.length(); i++) {
                if (!Character.isWhitespace(sc.charAt(i))) {
                    return false;
                }
            }
            return true;
        } else {
            return true;
        }
    }

    public static void main(String[] args) {
        Boolean empty = isEmpty("    ");
        System.out.println(isBlank("    "));
        System.out.println(isBlank("  1  "));
        System.out.println(empty);
    }
}
举报

相关推荐

0 条评论