org.apache.commons.lang3.StringUtils类中isBlank和isEmpty方法的区别

时间:2023-02-16 19:15:35

相信很多java程序员在写代码的时候遇到判断某字符串是否为空的时候会用到StringUtils类中isBlank和isEmpty方法,这两个方法到底有什么区别呢?我们用一段代码来阐述这个区别吧:

     @Test
public void blankEmpty() {
String str = " ";
System.out.println("Is empty ? " + StringUtils.isEmpty(str));
System.out.println("Is blank ? " + StringUtils.isBlank(str));
}

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAYIAAABFCAIAAADIAnZmAAAIYklEQVR4nO2dW5qsKgyFHRcDYjyMhsk4GPpBLSGEEEALrV7/1w/niBduWZWAZi8BAACmssyuAADgvwMZAhs+LCasfaX/htU9uB9ePEazZcgsYbGT63ArzoRlCcbNrkcNZ4L1naVPwYdl2f9c2Ry3Edn/OLsV5uSTZei+MTK1Lh1GlqFoXBcbnNmrsrroODeWyUhHf6SbvA3G8EPubXb5JWpVaNGtrK4iQ/IJ1csvwSxBmMNy6dMQhnV1lYkkzMmHc+sY3Wwpggz5sEQN23QhqYqXRivXZm/TIz4sS3C1aXGlEVZbdA/PlyFvpUfIpQ9EsJlKW3Rz8oHcPUbTZIiqRgj2UhlyJhhX/3VijXD3lRrd42qLbOR85Q+VSwW2Jpz+XVxtz7mNVlVqDwcz9j3z30NNXzW5QiZrxcc7Nm6oVEPsiVsfLFdz1maoC88FGqU5adKrmg3eM8O3l9hz4D41jGtFpk0pPiqNYFxzR0ypXKuQhiNupV0q24JmjFLU3hB/gkKGcuPfrzVhVTjJF8qQ3CKimy71zOVSmdUlfv421+kJXd7Q1g9nqWfmaLWvml2hwrgbO1xaJR1BW1DeTm9INydbndPNJhMfPBsLu7lgx3Fz/Ec8zbZlKcONI98oMhl8MlXkWpHpbZZgoi6t2IJujFL0a0N5+2syVFoS2iq3HeyToX5KLeLa4u3R9XJpjXxdk0ymIRkiFRMHhaVjVSg3hriSI6UVdJtBfTKknJOtE9JmFWa9co19lRbI2TGSwyipVtwUMovaFno27NQ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是否为0,而isEmpty方法则不会忽略空格,直接计算str的长度,长度大于0则返回false.

org.apache.commons.lang3.StringUtils类中isBlank和isEmpty方法的区别的更多相关文章

  1. struts2中的错误--java.lang.NoClassDefFoundError: org/apache/commons/lang3/StringUtils

    2013-4-7 10:13:56 org.apache.catalina.startup.HostConfig checkResources 信息: Reloading context [/chap ...

  2. org.apache.commons.lang.StringUtils类

    org.apache.commons.lang.StringUtils类 本文摘自:(http://www.blogjava.net/japper/archive/2012/05/23/378946. ...

  3. spring异常记录-----java.lang.NoClassDefFoundError: org/apache/commons/lang3/StringUtils

    今天在练习怎样SSH中进行单元測试的时候出现下列异常: SEVERE: Exception starting filter Struts2 java.lang.NoClassDefFoundError ...

  4. Hadoop java.lang.ClassNotFoundException: org.apache.commons.lang3.StringUtils

    .jar 学习好友推荐案例的时候,提交运行时报错找不到StringUtils java.lang.ClassNotFoundException: org.apache.commons.lang3.St ...

  5. Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang3.StringUtils

    1.错误叙述性说明 2014-7-10 23:12:23 org.apache.catalina.core.StandardContext filterStart 严重: Exception star ...

  6. NoClassDefFoundError: org/apache/commons/lang3/StringUtils

    出错信息: 2014-2-5 21:38:05 org.apache.catalina.core.StandardContext filterStart严重: Exception starting f ...

  7. ERROR----java.lang.NoClassDefFoundError: org/apache/commons/lang3/StringUtils

    2013-4-28 13:17:57 org.apache.catalina.core.StandardContext filterStart 严重: Exception starting filte ...

  8. 关于Integer类中parseInt()和valueOf()方法的区别以及int和String类性的转换.以及String类valueOf()方法

    Integer类中的. 关于parseInt()方法的API文档.  返回的是int类型的 关于valueOf()方法的API文档 返回的是Integer类型的. 关于intValue()方法的API ...

  9. org.apache.commons.lang3.StringUtils中的StringUtils常用方法

    https://my.oschina.net/funmo/blog/615202?p=1 public static void TestStr(){ //null 和 ""操作~~ ...

随机推荐

  1. Linux监控工具介绍系列——smem

    smem工具介绍 smem是Linux系统上的一款可以生成多种内存耗用报告的命令行工具.与现有工具不一样的是smem可以报告实际使用的物理内存(PSS),这是一种更有意义的指标.可以衡量虚拟内存系统的 ...

  2. echo 单引号和双引号

    echo输出 $key=value echo "$key" echo 后面带双引号的话,双引号里面的内容会翻译,输出value echo '$key' echo后面带单引号的话,双 ...

  3. Ext.js中的tip事件实际使用

    Ext.onReady(function () { // Init the singleton. Any tag-based quick tips will start working. Ext.ti ...

  4. 史上最全的 Java 新手问题汇总

    史上最全的 Java 新手问题汇总   Java是目前最流行的编程语言之一——它可以用来编写Windows程序或者是Web应用,移动应用,网络程序,消费电子产品,机顶盒设备,它无处不在. 有超过30亿 ...

  5. Introduction to Deep Neural Networks

    Introduction to Deep Neural Networks Neural networks are a set of algorithms, modeled loosely after ...

  6. idea集成svn插件

    1.需要在机器上安装一个SVN客户端命令行程序,可以到这里下载对应的安装程序:http://subversion.apache.org/packages.html#windows 我选择的是torto ...

  7. Asp.net core WebApi 使用Swagger生成帮助页

    最近我们团队一直进行.net core的转型,web开发向着前后端分离的技术架构演进,我们后台主要是采用了asp.net core webapi来进行开发,开始每次调试以及与前端人员的沟通上都存在这效 ...

  8. redis 设置认证密码

    通过修改redis配置文件(redis.conf)修改验证密码.(重启生效) requirepass myRedis 客户端通过密码登录redis并进行操作 redis-cli -h 127.0.0. ...

  9. 交叉编译 tcpdump

    目录 1. 下载 tcpdump 2. 交叉编译 3. 相关说明 1. 下载 tcpdump 官网:http://www.tcpdump.org/ 2. 交叉编译 交叉编译libpcap: $ wge ...

  10. Maven替换为国内仓库

    <mirror> <id>nexus-aliyun</id> <mirrorOf>central</mirrorOf> <name&g ...