zoukankan      html  css  js  c++  java
  • StringUtils类中isEmpty与isBlank的区别

    org.apache.commons.lang3 提供了String常用的操作,常用的有isEmpty(String str);isBlank(String str); 判断字符串是否为空、null、""等。
    <!--apache commons-->
    <dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-lang3</artifactId>
    <version>3.5</version>
    </dependency>

    StringUtils提供了许多的方法,可以通过StringUtils.xxx 看到,如下。

    1.StringUtils.isEmpty(str) 判断字符串内容是否为空,为空标准是str==null || str.length()==0,包括null、""。
    System.out.println(StringUtils.isEmpty(null));   结果 true
    System.out.println(StringUtils.isEmpty("")); 结果true
    System.out.println(StringUtils.isEmpty(" ")); 结果false
    System.out.println(StringUtils.isEmpty("aaa")); 结果false
    StringUtils.isNotEmpty(str) 等价于!str.isEmpty(str) 表示非空。

    2.StringUtils.isBlank(str)判断字符串内容为空,内容为空包括 null、""、" "。
    System.out.println(StringUtils.isBlank(null));  结果是true
    System.out.println(StringUtils.isBlank("")); 结果是true
    System.out.println(StringUtils.isBlank(" ")); 结果是true
    System.out.println(StringUtils.isBlank("aaa")); 结果是false
    
    
  • 相关阅读:
    linux目录跳转的好武器z.sh
    找工作的程序员必懂的Linux
    11-面向对象4
    10-面向对象3
    09-面向对象2
    08-面向对象1
    06-数组
    3.5-乘法运算器设计
    3.2-定点数补码加减运算器设计
    4.12-虚拟存储器
  • 原文地址:https://www.cnblogs.com/ming-blogs/p/10654463.html
Copyright © 2011-2022 走看看