这边首先以一个简单的测试代码来解释这两者的区别:

@Test
void stringTest(){
String a = " ";
boolean empty = StringUtils.isEmpty(a);
boolean blank = StringUtils.isBlank(a);
System.out.println(empty);//false
System.out.println(blank);//true
}

由此可以看出“空格”使用isEmpty结果是false,而使用isBlank时结果是true。

再截取源码来看看:

isEmpty()

public static boolean isEmpty(CharSequence cs) {
return cs == null || cs.length() == 0;
}

isBlank()

public static boolean isBlank(CharSequence cs) {
int strLen;
if (cs != null && (strLen = cs.length()) != 0) {
for(int i = 0; i < strLen; ++i) {
       // 判断字符是否为空格、制表符、tab
if (!Character.isWhitespace(cs.charAt(i))) {
return false;
}
}
return true;
} else {
return true;
}
}

综上:isBlank 是在 isEmpty 的基础上进行了为空(字符串都为空格、制表符、tab 的情况)的判断。(一般更为常用)

StringUtils里的isEmpty和isBlank的区别的更多相关文章

  1. StringUtils类中isEmpty与isBlank的区别

    org.apache.commons.lang.StringUtils类提供了String的常用操作,最为常用的判空有如下两种isEmpty(String str)和isBlank(String st ...

  2. StringUtils类中 isEmpty() 与 isBlank()的区别

    org.apache.commons.lang.StringUtils类提供了String的常用操作,最为常用的判空有如下两种isEmpty(String str)和isBlank(String st ...

  3. java判断一个字符串是否为空,isEmpty和isBlank的区别

    转载于:https://blog.csdn.net/liusa825983081/article/details/78246792 实际应用中,经常会用到判断字符串是否为空的逻辑 比较简单的就是用 S ...

  4. StringUtils里的isEmpty方法和isBlank方法的区别

    原文地址:https://blog.csdn.net/a1102325298/article/details/80410740 isEmpty public static boolean isEmpt ...

  5. java中StringUtils中isEmpty 和isBlank的区别

    StringUtils在commons-lang-2.2.jar包中:org.apache.commons.lang.StringUtils ; StringUtils方法的操作对象是java.lan ...

  6. StringUtils中isEmpty 和isBlank的区别

    StringUtils在commons-lang-2.2.jar包中:org.apache.commons.lang.StringUtils ; StringUtils方法的操作对象是java.lan ...

  7. StringUtils.isEmpty()和isBlank()的区别

    一.概述 两种判断字符串是否为空的用法都是在程序开发时常用的,相信不少同学在这种简单的问题上也吃过亏,到底有什么区别,使用有什么讲究,带着问题往下看. 二.jar包 commons-lang3-3.5 ...

  8. StringUtils中 isEmpty 和isBlank的区别

    StringUtils方法的操作对象是java.lang.String类型的对象,是JDK提供的String类型操作方法的补充,并且是null安全的(即如果输入参数String为null则不会抛出Nu ...

  9. org.apache.commons.lang.StringUtils中isEmpty和isBlank的区别

    public static boolean isEmpty(String str) 判断某字符串是否为空,为空的标准是str==null或str.length()==0 StringUtils.isE ...

随机推荐

  1. [NOIP模拟测试9]题(Problem) 题解 (组合数全家桶+dp)

    达哥送分给我我都不要,感觉自己挺牛批. $type=0:$ 跟visit那题类似,枚举横向移动的步数直接推公式: $ans=\sum C_n^i \times C_i^{\frac{i}{2}} \t ...

  2. 关于ACL访问控制的一些问题:AntiACL

    @echo off title AntiACL Made By gwsbhqt color 0a reg query "HKU\S-1-5-19" >nul 2>nul ...

  3. ASP.NET Core学习——1

    ASP.NET Core介绍 ASP.NET Core是一个新的开源和跨平台的框架,用于构建如Web应用.物联网(IoT)应用和移动后端应用等连接到互联网的基于云的现代应用程序.ASP.NET Cor ...

  4. 关闭windows的DEP

    1.与开启dep时一样,按组合键win+r打开运行窗口,输入cmd并按回车,如图所示:    2.调出命令提示符窗口后,输入bcdedit.exe/set {current} nx AlwaysOff ...

  5. VS2010 下C++使用UTF8编码

    http://www.nubaria.com/en/blog/?p=289 #pragma execution_character_set("utf-8")

  6. Ubuntu 没有 无线网 RTL8821ce 8111 8186

    1.将ubuntu的linux内核版本更改到4.14(其他版本不兼容这个无线网卡的驱动) 1.1 找到内核版本 #到 Ubuntu网站http://kernel.ubuntu.com/~kernel- ...

  7. Java反射机制调用私有方法

    1.获取目标类: 每个类都有一个class属性,通过实体类的class属性获取: Class clazz = Person.class 通过对象获取.  Person p1 = new Person( ...

  8. hibernate 中createQuery与createSQLQuery两者区别

    hibernate 中createQuery与createSQLQuery两者区别是:前者用的hql语句进行查询,后者可以用sql语句查询前者以hibernate生成的Bean为对象装入list返回, ...

  9. 11-Ubuntu-根目录下各目录的功能详细介绍

    转自: https://www.cnblogs.com/yudar/p/5809219.html 注:总结的非常详细

  10. linux下读取移动硬盘

    前提是安装了ntfs-3g软件,系统才能识别到移动硬盘. 第一步.fdisk -l    该命令查看系统识别到的磁盘,如果移动硬盘系统能够识别,    在屏幕上会输出“/dev/sdb1”之类的字样. ...