Class StringUtils
-
Method Summary
Modifier and TypeMethodDescriptionstatic String[]Convert a comma delimited list into an array of strings.static String[]delimitedListToStringArray(String str, String delimiter) Take aStringthat is a delimited list and convert it into aStringarray.static booleanisBlank(CharSequence cs) Checks if a CharSequence is empty (""), null or whitespace only.static booleanisEmpty(CharSequence cs) Checks if a CharSequence is empty ("") or null.static intlength(CharSequence cs) Gets a CharSequence length or0if the CharSequence isnull.static StringRemoves control characters (char <= 32) from both ends of this String, handlingnullby returningnull.static StringtrimToEmpty(String str) Removes control characters (char <= 32) from both ends of this String returning an empty String ("") if the String is empty ("") after the trim or if it isnull.static StringtrimToNull(String str) Removes control characters (char <= 32) from both ends of this String returningnullif the String is empty ("") after the trim or if it isnull.
-
Method Details
-
trim
Removes control characters (char <= 32) from both ends of this String, handling
nullby returningnull.The String is trimmed using
String.trim(). Trim removes start and end characters <= 32.StringUtils.trim(null) = null StringUtils.trim("") = "" StringUtils.trim(" ") = "" StringUtils.trim("abc") = "abc" StringUtils.trim(" abc ") = "abc"- Parameters:
str- the String to be trimmed, may be null- Returns:
- the trimmed string,
nullif null String input
-
trimToEmpty
Removes control characters (char <= 32) from both ends of this String returning an empty String ("") if the String is empty ("") after the trim or if it is
null.The String is trimmed using
String.trim(). Trim removes start and end characters <= 32.StringUtils.trimToEmpty(null) = "" StringUtils.trimToEmpty("") = "" StringUtils.trimToEmpty(" ") = "" StringUtils.trimToEmpty("abc") = "abc" StringUtils.trimToEmpty(" abc ") = "abc"- Parameters:
str- the String to be trimmed, may be null- Returns:
- the trimmed String, or an empty String if
nullinput
-
trimToNull
Removes control characters (char <= 32) from both ends of this String returning
nullif the String is empty ("") after the trim or if it isnull.The String is trimmed using
String.trim(). Trim removes start and end characters <= 32.StringUtils.trimToNull(null) = null StringUtils.trimToNull("") = null StringUtils.trimToNull(" ") = null StringUtils.trimToNull("abc") = "abc" StringUtils.trimToNull(" abc ") = "abc"- Parameters:
str- the String to be trimmed, may be null- Returns:
- the trimmed String,
nullif only chars <= 32, empty or null String input
-
isEmpty
Checks if a CharSequence is empty ("") or null.
StringUtils.isEmpty(null) = true StringUtils.isEmpty("") = true StringUtils.isEmpty(" ") = false StringUtils.isEmpty("bob") = false StringUtils.isEmpty(" bob ") = false- Parameters:
cs- the CharSequence to check, may be null- Returns:
trueif the CharSequence is empty or null
-
isBlank
Checks if a CharSequence is empty (""), null or whitespace only.
Whitespace is defined by
Character.isWhitespace(char).StringUtils.isBlank(null) = true StringUtils.isBlank("") = true StringUtils.isBlank(" ") = true StringUtils.isBlank("bob") = false StringUtils.isBlank(" bob ") = false- Parameters:
cs- the CharSequence to check, may be null- Returns:
trueif the CharSequence is null, empty or whitespace only
-
length
Gets a CharSequence length or0if the CharSequence isnull.- Parameters:
cs- a CharSequence ornull- Returns:
- CharSequence length or
0if the CharSequence isnull.
-
commaDelimitedListToStringArray
-
delimitedListToStringArray
Take aStringthat is a delimited list and convert it into aStringarray.A single
delimitermay consist of more than one character, but it will still be considered as a single delimiter string, rather than as a bunch of potential delimiter characters. Delimiter can be escaped by prefixing it with a backslash (\).Values are trimmed, and are added to the resulting array only if not blank. Therefore two consecutive delimiters are treated as a single delimiter.
A
nulldelimiter is treated as no delimiter and returns an array with the originalstrstring as single element. An empty delimiter splits the input string at each character.A
nullinput returns an empty array.- Parameters:
str- the inputString(potentiallynullor empty)delimiter- the delimiter between elements- Returns:
- an array of the tokens in the list
-