0
点赞
收藏
分享

微信扫一扫

utils002_字符串的非空判断

ITWYY 2022-04-20 阅读 40
java
package com.jingsong.test;

import org.apache.commons.lang3.StringUtils;

/**
 * @author jingsong
 * @date 2022/4/20 0:03
 * @description
 *      对于字符串的操作推荐使用下面的两个jar包
 *        1. StringUtils apache出品
 *          https://mvnrepository.com/artifact/org.apache.commons/commons-lang3
 *        2. StrUtil 中文注释,功能强大
 *          https://mvnrepository.com/artifact/cn.hutool/hutool-all
 */
public class StringTest {
    public static void main(String[] args) {
        String  a = "",
                b = " ",
                c = "hehe",
                d = "  Q  ",
                e = null;
        // 1. empty是判断是否为空,blank是判断是否有文字
        System.out.println(StringUtils.isEmpty(b));// false
        System.out.println(StringUtils.isBlank(b));// true
        System.out.println();

        // 2,3,4 中的方法可以同时判断多个,更加方便
        // 2. 至少有一个为空
        System.out.println(StringUtils.isAnyEmpty(a, c, d, e));// true
        System.out.println(StringUtils.isAnyEmpty(b, c, d));// false
        System.out.println();

        // 3. 没一个空的
        System.out.println(StringUtils.isNoneEmpty(a,c));// false
        System.out.println(StringUtils.isNoneEmpty(b, c, d));// true
        System.out.println();

        // 4. 都是空的
        System.out.println(StringUtils.isAllEmpty(a, e));// true
        System.out.println(StringUtils.isAllEmpty(a, b, c, d));// false
        System.out.println();
    }
}

举报

相关推荐

0 条评论