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
    
    
  • 相关阅读:
    Asp.Net上传大文件(页面超时)
    C#文件的大小
    设计模式简单工厂、工厂方法、抽象工厂方法
    设计模式迭代器模式
    Asp.Net下载文件
    设计模式桥接模式
    CSS尺寸(Dimensions)
    设计模式单件模式
    Android 换肤
    像QQtab切换效果的例子
  • 原文地址:https://www.cnblogs.com/ming-blogs/p/10654463.html
Copyright © 2011-2022 走看看