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