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) 等价于!StringUtils.isEmpty(str) 表示非空。
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
StringUtils.isNotBlank(str) 等价于!StringUtils.isBlank(str) 表示非空。
注意使用StringUtils需要引入依赖:
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>