前言:
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字符串判空】 - 滌新雲 - 博客園