isNotEmpty將空格也作爲參數,isNotBlank則排除空格參數
Note
StringUtils方法的操作對象是java.lang.String類型的對象,是JDK提供的String類型操作方法的補充,並且是null安全的(即如果輸入參數String爲null則不會拋出NullPointerException,而是做了相應處理,例如,如果輸入爲null則返回也是null等,具體可以查看源代碼)。
除了構造器,StringUtils中一共有130多個方法,並且都是static的,所以我們可以這樣調用StringUtils.xxx()
-
public static boolean isEmpty(String str)
判斷某字符串是否爲空,爲空的標準是str==null或str.length()==0 -
public static boolean isNotEmpty(String str)
判斷某字符串是否非空,等於!isEmpty(String str)
public static boolean isBlank(String str)
判斷某字符串是否爲空或長度爲0或由空白符(whitespace)構成
- public static boolean isNotBlank(String str)
判斷某字符串是否不爲空且長度不爲0且不由空白符(whitespace)構成,等於!isBlank(String str)
其他方法介紹:
4. . public static String trim(String str)
去掉字符串兩端的控制符(control characters, char <= 32),如果輸入爲null則返回null
- public static String trimToNull(String str)
去掉字符串兩端的控制符(control characters, char <= 32),如果變爲null或"",則返回null
public static String trimToEmpty(String str)
去掉字符串兩端的控制符(control characters, char <= 32),如果變爲null或"",則返回""
-
public static String strip(String str)
去掉字符串兩端的空白符(whitespace),如果輸入爲null則返回null -
public static String stripToNull(String str)
去掉字符串兩端的空白符(whitespace),如果變爲null或"",則返回null -
public static String stripToEmpty(String str)
去掉字符串兩端的空白符(whitespace),如果變爲null或"",則返回""
其他方法可以具體參考包org.apache.commons.lang的API