zoukankan      html  css  js  c++  java
  • IsEmpty和isBlank区别

    1. 详细测试结论如下
    • isEmpty ----》会把空格当成元素
    • isBlank ----》相反

    class Test001 {
        static void t01() {
            String A = "  ";
            String B = "";
            String C = null;
    
            // 长度
            System.out.println(A.length());
    
            // 测试 isEmpty
            /* 从效果来看,当A="",字符中有空格时,IsEmpty是算他不为空的*/
            System.out.println("======测试 isEmpty======");
            System.out.println(StringUtils.isEmpty(A)); //会把空格当成元素
            System.out.println(StringUtils.isEmpty(B));
            System.out.println(StringUtils.isEmpty(C));
    
            // 测试 isBlank
            System.out.println("======测试 isBlank======");
            System.out.println(StringUtils.isBlank(A)); //不会把空格当成元素
            System.out.println(StringUtils.isBlank(B));
            System.out.println(StringUtils.isBlank(C));
    
            /* TODO 结论: isEmpty 等价于 str == null || str.length == 0;isBlank  等价于 str == null || str.length == 0 || str.trim().length == 0*/
            /* TODO 结论02: isNotEmpty和isNotBlank 结果相反*/
    
            /* 输出:
            2
                    ======测试 isEmpty======
            false
            true
            true
                    ======测试 isBlank======
            true
            true
            true
    
            Process finished with exit code 0*/
    
        }
    }
    
  • 相关阅读:
    such用法
    divorce用法
    towel用法
    go for用法
    catch on用法
    incredibly用法
    mess用法
    dentist用法
    steer clear of用法
    incredible
  • 原文地址:https://www.cnblogs.com/Twittery/p/14434994.html
Copyright © 2011-2022 走看看