首先要利用StringUtils类的方法,需要调用

import org.apache.commons.lang3.StringUtils;

因此需要引用org.apache.commons.lang3包。

Maven下的引用

<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-lang3</artifactId>
    <version>3.8</version>
</dependency>

Gradle引用 

// https://mvnrepository.com/artifact/org.apache.commons/commons-lang3
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.8'
 

区别 

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

str.length > 0 && str.trim().length > 0 ---> str.length > 0

示例

StringUtils中 isNotEmpty 和isNotBlank的区别

相关文章: