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

posted @ 2019-04-04 13:55  明天,你好啊  阅读(2915)  评论(0编辑  收藏  举报