【Java】【8】StringUtils中isNotEmpty和isNotBlank的区别

前言:

1,StringUtils.isNotEmpty(str)和StringUtils.isNotBlank(str)都是用来做非空判断的

2,通常用isNotBlank

3,import org.apache.commons.lang.StringUtils;

正文:

1,主要差别:isNotBlank多了去除字符串前后空格再做判断

isNotEmpty(str) 等价于 str != null && str.length > 0
isNotBlank(str) 等价于 str != null && str.length > 0 && str.trim().length > 0
同理
isEmpty 等价于 str == null || str.length == 0
isBlank 等价于 str == null || str.length == 0 || str.trim().length == 0

2,StringUtils需要的jar包

pom.xml

<dependency>
    <groupId>commons-lang</groupId>
    <artifactId>commons-lang</artifactId>
    <version>2.6</version>
</dependency>

参考博客:

1,StringUtils中 isNotEmpty 和isNotBlank的区别【java字符串判空】 - 涤新云 - 博客园

https://www.cnblogs.com/dixinyunpan/p/6088612.html

原文地址:https://www.cnblogs.com/huashengweilong/p/10691553.html