java-第三方工具去做一些校验

推荐大家使用第三方 jar 的工具类去做判空。比如:从 Map 中取一个 key 的值,可以用 MapUtils 这个类;对字符串判空使用 StringUtils 这个类;对集合进行判空使用 CollectionUtils 等等

 

列举字符串的判断空的第三方公工具

StringUtils

 

    @Test
    void contextLoads() {
        System.out.println(StringUtils.isBlank("yyy"));
        System.out.println(StringUtils.isBlank("   "));
        System.out.println(StringUtils.isBlank(""));
        //false
        //true
        //true
    }

 

    @Test
    void contextLoads() {
        //这是String类自带的
        System.out.println("  ".isEmpty());
        System.out.println("".isEmpty());
        System.out.println("hello".isEmpty());
        //false
        //true
        //false
    }

 

posted @ 2020-06-23 19:18  小丑quan  阅读(196)  评论(0)    收藏  举报