The StringUtils method operates on java.lang.String objects, which complement the String operation methods provided by the JDK. NullPointerException is not thrown if the input parameter String is null. For example, null is returned if the input parameter String is null. For details, see the source code. In addition to the constructor, there are over 130 methods in StringUtils, all of which are static, so we can call stringutils.xxx () like this
1. public static boolean isEmpty(String str)
STR ==null or str.length()==0
StringUtils.isEmpty(null) = true
StringUtils.isEmpty("") = true
// Note that Spaces in StringUtils are not null
StringUtils.isEmpty("") = false
StringUtils.isEmpty("") = false
StringUtils.isEmpty("bob") = false
StringUtils.isEmpty(" bob ") = false
Copy the code
2. public static boolean isNotEmpty(String str)
Check if a string is not empty, equal to! isEmpty(String str)
3. public static boolean isBlank(String str)
Determines whether a string is empty or has a length of 0 or consists of whitespace characters
StringUtils.isBlank(null) = true
StringUtils.isBlank("") = true
StringUtils.isBlank("") = true
StringUtils.isBlank("") = true
StringUtils.isBlank("\t \n \f \r") = true // For TAB, line feed, page feed, and carriage return characters
StringUtils.isBlank() // both are blank characters
StringUtils.isBlank("\b") = false //"\b" is the word boundary
StringUtils.isBlank("bob") = false
StringUtils.isBlank(" bob ") = false
Copy the code
4. public static boolean isNotBlank(String str)
Determines if a string is not empty, has a length of 0, and is not whitespace, equal to! isBlank(String str)
5. public static String trim(String str)
Remove control characters (Control characters, char <= 32) at both ends of the string, and return null if null is entered
StringUtils.trim(null) = null
StringUtils.trim("") = ""
StringUtils.trim("") = ""
StringUtils.trim(" \b \t \n \f \r ") = ""
StringUtils.trim(" \n\tss \b") = "ss"
StringUtils.trim(" d d dd ") = "d d dd"
StringUtils.trim("dd ") = "dd"
StringUtils.trim(" dd ") = "dd"
Copy the code
6. public static String trimToNull(String str)
Remove control characters (Control characters, char <= 32) at both ends of the string, and return null if null or “”
StringUtils.trimToNull(null) = null
StringUtils.trimToNull("") = null
StringUtils.trimToNull("") = null
StringUtils.trimToNull(" \b \t \n \f \r ") = null
StringUtils.trimToNull(" \n\tss \b") = "ss"
StringUtils.trimToNull(" d d dd ") = "d d dd"
Copy the code