自学内容网 自学内容网

org.springframework.util.StringUtils 下StringUtils工具类

目录

1.isEmpty

1.1.可以判断字符串是否为空或 null 

1.2.可以判断Integer类型的数据是否为空


1.isEmpty

1.1.可以判断字符串是否为空或 null 

 @Test
    public void test() {
        /**
         * StringUtils.isEmpty 判断是空
         */
        String username = "123456";
        System.out.println(StringUtils.isEmpty(username));   //false

        //username2为空,那么它是怎么判断的?
        String username2 = "";
        System.out.println(StringUtils.isEmpty(username2));   //true

        //username3为空格,那么它是怎么判断的?认为空格也是字符串
        String username3 = " ";
        System.out.println(StringUtils.isEmpty(username3));   //false

        String username4 = "路飞";
        System.out.println(StringUtils.isEmpty(username4));   //false

        String username5 = "....";
        System.out.println(StringUtils.isEmpty(username5));   //false


    }

1.2.可以判断Integer类型的数据是否为空

@Test
    public void test5(){
        Integer one=2;
        Integer two=null;

        if (StringUtils.isEmpty(one)){
            System.out.println("one是空的");
        }else {
            System.out.println("one不是空的");
        }

        if (StringUtils.isEmpty(two)){
            System.out.println("two是空的");
        }else {
            System.out.println("two不是空的");
        }
    }


原文地址:https://blog.csdn.net/m0_59690068/article/details/135778021

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!