public class StringUtils extends Object
| 限定符和类型 | 字段和说明 |
|---|---|
static String |
EMPTY
The empty String
"". |
static String |
EMPTY_STRING |
| 构造器和说明 |
|---|
StringUtils() |
| 限定符和类型 | 方法和说明 |
|---|---|
static String |
capitalize(String str)
Capitalizes a String changing the first letter to title case as
per
Character.toTitleCase(char). |
static boolean |
endsWith(String str,
String suffix)
Check if a String ends with a specified suffix.
|
static boolean |
endsWithIgnoreCase(String str,
String suffix)
Case insensitive check if a String ends with a specified suffix.
|
static String |
escapeBytes(byte[] input)
Like
#escapeBytes(ByteString), but used for byte array. |
static String |
escapeJava(String str)
Escapes the characters in a
String using Java String rules. |
static void |
escapeJava(Writer out,
String str)
Escapes the characters in a
String using Java String rules to a Writer. |
static boolean |
isEmpty(Object[] array)
Checks if an array of Objects is empty or
null. |
static boolean |
isEmpty(String str)
Checks if a String is empty ("") or null.
|
static String |
removeEnd(String str,
String remove)
Removes a substring only if it is at the end of a source string,
otherwise returns the source string.
|
static String |
removeEndIgnoreCase(String str,
String remove)
Case insensitive removal of a substring if it is at the end of a source
string, otherwise returns the source string.
|
static String |
removeStart(String str,
String remove)
Removes a substring only if it is at the begining of a source string,
otherwise returns the source string.
|
static String |
removeStartIgnoreCase(String str,
String remove)
Case insensitive removal of a substring if it is at the begining of a
source string, otherwise returns the source string.
|
static String[] |
split(String str)
Splits the provided text into an array, using whitespace as the separator.
|
static String[] |
split(String str,
char separatorChar)
Splits the provided text into an array, separator specified.
|
static String[] |
split(String str,
String separatorChars)
Splits the provided text into an array, separators specified.
|
static String[] |
split(String str,
String separatorChars,
int max)
Splits the provided text into an array with a maximum length, separators specified.
|
static String[] |
splitByWholeSeparator(String str,
String separator)
Splits the provided text into an array, separator string specified.
|
static String[] |
splitByWholeSeparator(String str,
String separator,
int max)
Splits the provided text into an array, separator string specified.
|
static String[] |
splitByWholeSeparatorPreserveAllTokens(String str,
String separator)
Splits the provided text into an array, separator string specified.
|
static String[] |
splitByWholeSeparatorPreserveAllTokens(String str,
String separator,
int max)
Splits the provided text into an array, separator string specified.
|
static boolean |
startsWith(String str,
String prefix)
Check if a String starts with a specified prefix.
|
static boolean |
startsWithAny(String string,
String[] searchStrings)
Check if a String starts with any of an array of specified strings.
|
static boolean |
startsWithIgnoreCase(String str,
String prefix)
Case insensitive check if a String starts with a specified prefix.
|
static int |
stringToInt(String str,
int defaultValue)
已过时。
Use
toInt(String, int) This method will be removed in Commons Lang 3.0 |
static String |
substringAfterLast(String str,
String separator)
Gets the substring after the last occurrence of a separator.
|
static String |
substringBefore(String str,
String separator)
Gets the substring before the first occurrence of a separator.
|
static String |
substringBeforeLast(String str,
String separator)
Gets the substring before the last occurrence of a separator.
|
static int |
toInt(String str)
Convert a
String to an int, returning zero if the conversion fails. |
static int |
toInt(String str,
int defaultValue)
Convert a
String to an int, returning a default value if the conversion fails. |
static long |
toLong(String str)
Convert a
String to an long, returning a default value if the conversion fails. |
static long |
toLong(String str,
long defaultValue)
Convert a
String to an long, returning a default value if the conversion fails. |
static String |
toLowerCase(String str)
To lower case.
|
static String |
trimToEmpty(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 is
null. |
static String |
uncapitalize(String str)
Uncapitalizes a String, changing the first character to lower case as
per
Character.toLowerCase(int). |
static String |
unescapeJava(String str)
Unescapes any Java literals found in the
String. |
static void |
unescapeJava(Writer out,
String str)
Unescapes any Java literals found in the
String to a Writer. |
public static boolean endsWith(String str, String suffix)
Check if a String ends with a specified suffix.
nulls are handled without exceptions. Two null
references are considered to be equal. The comparison is case sensitive.
StringUtils.endsWith(null, null) = true
StringUtils.endsWith(null, "abcdef") = false
StringUtils.endsWith("def", null) = false
StringUtils.endsWith("def", "abcdef") = true
StringUtils.endsWith("def", "ABCDEF") = false
str - the String to check, may be nullsuffix - the suffix to find, may be nulltrue if the String ends with the suffix, case
sensitive, or both nullString.endsWith(String)public static boolean endsWithIgnoreCase(String str, String suffix)
Case insensitive check if a String ends with a specified suffix.
nulls are handled without exceptions. Two null
references are considered to be equal. The comparison is case
insensitive.
StringUtils.endsWithIgnoreCase(null, null) = true
StringUtils.endsWithIgnoreCase(null, "abcdef") = false
StringUtils.endsWithIgnoreCase("def", null) = false
StringUtils.endsWithIgnoreCase("def", "abcdef") = true
StringUtils.endsWithIgnoreCase("def", "ABCDEF") = false
str - the String to check, may be nullsuffix - the suffix to find, may be nulltrue if the String ends with the suffix, case
insensitive, or both nullString.endsWith(String)public static String removeEnd(String str, String remove)
Removes a substring only if it is at the end of a source string, otherwise returns the source string.
A null source string will return null. An empty
("") source string will return the empty string. A null
search string will return the source string.
StringUtils.removeEnd(null, *) = null
StringUtils.removeEnd("", *) = ""
StringUtils.removeEnd(*, null) = *
StringUtils.removeEnd("www.domain.com", ".com.") = "www.domain.com"
StringUtils.removeEnd("www.domain.com", ".com") = "www.domain"
StringUtils.removeEnd("www.domain.com", "domain") = "www.domain.com"
StringUtils.removeEnd("abc", "") = "abc"
str - the source String to search, may be nullremove - the String to search for and remove, may be nullnull
if null String inputpublic static String removeEndIgnoreCase(String str, String remove)
Case insensitive removal of a substring if it is at the end of a source string, otherwise returns the source string.
A null source string will return null. An empty
("") source string will return the empty string. A null
search string will return the source string.
StringUtils.removeEnd(null, *) = null
StringUtils.removeEnd("", *) = ""
StringUtils.removeEnd(*, null) = *
StringUtils.removeEnd("www.domain.com", ".com.") = "www.domain.com."
StringUtils.removeEnd("www.domain.com", ".com") = "www.domain"
StringUtils.removeEnd("www.domain.com", "domain") = "www.domain.com"
StringUtils.removeEnd("abc", "") = "abc"
str - the source String to search, may be nullremove - the String to search for (case insensitive) and remove, may be
nullnull
if null String inputpublic static boolean isEmpty(String str)
Checks if a String is empty ("") or null.
StringUtils.isEmpty(null) = true
StringUtils.isEmpty("") = true
StringUtils.isEmpty(" ") = false
StringUtils.isEmpty("bob") = false
StringUtils.isEmpty(" bob ") = false
NOTE: This method changed in Lang version 2.0. It no longer trims the String. That functionality is available in isBlank().
str - the String to check, may be nulltrue if the String is empty or nullpublic static String removeStart(String str, String remove)
Removes a substring only if it is at the begining of a source string, otherwise returns the source string.
A null source string will return null. An empty
("") source string will return the empty string. A null
search string will return the source string.
StringUtils.removeStart(null, *) = null
StringUtils.removeStart("", *) = ""
StringUtils.removeStart(*, null) = *
StringUtils.removeStart("www.domain.com", "www.") = "domain.com"
StringUtils.removeStart("domain.com", "www.") = "domain.com"
StringUtils.removeStart("www.domain.com", "domain") = "www.domain.com"
StringUtils.removeStart("abc", "") = "abc"
str - the source String to search, may be nullremove - the String to search for and remove, may be nullnull
if null String inputpublic static String removeStartIgnoreCase(String str, String remove)
Case insensitive removal of a substring if it is at the begining of a source string, otherwise returns the source string.
A null source string will return null. An empty
("") source string will return the empty string. A null
search string will return the source string.
StringUtils.removeStartIgnoreCase(null, *) = null
StringUtils.removeStartIgnoreCase("", *) = ""
StringUtils.removeStartIgnoreCase(*, null) = *
StringUtils.removeStartIgnoreCase("www.domain.com", "www.") = "domain.com"
StringUtils.removeStartIgnoreCase("www.domain.com", "WWW.") = "domain.com"
StringUtils.removeStartIgnoreCase("domain.com", "www.") = "domain.com"
StringUtils.removeStartIgnoreCase("www.domain.com", "domain") = "www.domain.com"
StringUtils.removeStartIgnoreCase("abc", "") = "abc"
str - the source String to search, may be nullremove - the String to search for (case insensitive) and remove, may be
nullnull
if null String inputpublic static boolean startsWith(String str, String prefix)
Check if a String starts with a specified prefix.
nulls are handled without exceptions. Two null
references are considered to be equal. The comparison is case sensitive.
StringUtils.startsWith(null, null) = true
StringUtils.startsWith(null, "abcdef") = false
StringUtils.startsWith("abc", null) = false
StringUtils.startsWith("abc", "abcdef") = true
StringUtils.startsWith("abc", "ABCDEF") = false
str - the String to check, may be nullprefix - the prefix to find, may be nulltrue if the String starts with the prefix, case
sensitive, or both nullString.startsWith(String)public static boolean startsWithAny(String string, String[] searchStrings)
Check if a String starts with any of an array of specified strings.
StringUtils.startsWithAny(null, null) = false
StringUtils.startsWithAny(null, new String[] {"abc"}) = false
StringUtils.startsWithAny("abcxyz", null) = false
StringUtils.startsWithAny("abcxyz", new String[] {""}) = false
StringUtils.startsWithAny("abcxyz", new String[] {"abc"}) = true
StringUtils.startsWithAny("abcxyz", new String[] {null, "xyz", "abc"}) = true
string - the String to check, may be nullsearchStrings - the Strings to find, may be null or emptytrue if the String starts with any of the the prefixes, case insensitive, or
both nullstartsWith(String, String)public static boolean startsWithIgnoreCase(String str, String prefix)
Case insensitive check if a String starts with a specified prefix.
nulls are handled without exceptions. Two null
references are considered to be equal. The comparison is case
insensitive.
StringUtils.startsWithIgnoreCase(null, null) = true
StringUtils.startsWithIgnoreCase(null, "abcdef") = false
StringUtils.startsWithIgnoreCase("abc", null) = false
StringUtils.startsWithIgnoreCase("abc", "abcdef") = true
StringUtils.startsWithIgnoreCase("abc", "ABCDEF") = true
str - the String to check, may be nullprefix - the prefix to find, may be nulltrue if the String starts with the prefix, case
insensitive, or both nullString.startsWith(String)public static String substringBefore(String str, String separator)
Gets the substring before the first occurrence of a separator. The separator is not returned.
A null string input will return null.
An empty ("") string input will return the empty string.
A null separator will return the input string.
StringUtils.substringBefore(null, *) = null
StringUtils.substringBefore("", *) = ""
StringUtils.substringBefore("abc", "a") = ""
StringUtils.substringBefore("abcba", "b") = "a"
StringUtils.substringBefore("abc", "c") = "ab"
StringUtils.substringBefore("abc", "d") = "abc"
StringUtils.substringBefore("abc", "") = ""
StringUtils.substringBefore("abc", null) = "abc"
str - the String to get a substring from, may be nullseparator - the String to search for, may be nullnull if null String inputpublic static String substringBeforeLast(String str, String separator)
Gets the substring before the last occurrence of a separator. The separator is not returned.
A null string input will return null.
An empty ("") string input will return the empty string.
An empty or null separator will return the input string.
StringUtils.substringBeforeLast(null, *) = null
StringUtils.substringBeforeLast("", *) = ""
StringUtils.substringBeforeLast("abcba", "b") = "abc"
StringUtils.substringBeforeLast("abc", "c") = "ab"
StringUtils.substringBeforeLast("a", "a") = ""
StringUtils.substringBeforeLast("a", "z") = "a"
StringUtils.substringBeforeLast("a", null) = "a"
StringUtils.substringBeforeLast("a", "") = "a"
str - the String to get a substring from, may be nullseparator - the String to search for, may be nullnull if null String inputpublic static String substringAfterLast(String str, String separator)
Gets the substring after the last occurrence of a separator. The separator is not returned.
A null string input will return null.
An empty ("") string input will return the empty string.
An empty or null separator will return the empty string if
the input string is not null.
StringUtils.substringAfterLast(null, *) = null
StringUtils.substringAfterLast("", *) = ""
StringUtils.substringAfterLast(*, "") = ""
StringUtils.substringAfterLast(*, null) = ""
StringUtils.substringAfterLast("abc", "a") = "bc"
StringUtils.substringAfterLast("abcba", "b") = "a"
StringUtils.substringAfterLast("abc", "c") = ""
StringUtils.substringAfterLast("a", "a") = ""
StringUtils.substringAfterLast("a", "z") = ""
str - the String to get a substring from, may be nullseparator - the String to search for, may be nullnull if null String inputpublic static String capitalize(String str)
Capitalizes a String changing the first letter to title case as
per Character.toTitleCase(char). No other letters are changed.
For a word based algorithm, see WordUtils#capitalize(String).
A null input String returns null.
StringUtils.capitalize(null) = null
StringUtils.capitalize("") = ""
StringUtils.capitalize("cat") = "Cat"
StringUtils.capitalize("cAt") = "CAt"
str - the String to capitalize, may be nullnull if null String inputWordUtils#capitalize(String),
uncapitalize(String)public static String escapeJava(String str)
Escapes the characters in a String using Java String rules.
Deals correctly with quotes and control-chars (tab, backslash, cr, ff, etc.)
So a tab becomes the characters '\\' and 't'.
The only difference between Java strings and JavaScript strings is that in JavaScript, a single quote must be escaped.
Example:
input string: He didn't say, "Stop!" output string: He didn't say, \"Stop!\"
str - String to escape values in, may be nullnull if null string inputpublic static void escapeJava(Writer out, String str) throws IOException
Escapes the characters in a String using Java String rules to a Writer.
A null string input has no effect.
out - Writer to write escaped string intostr - String to escape values in, may be nullIllegalArgumentException - if the Writer is nullIOException - if error occurs on underlying WriterescapeJava(java.lang.String)public static String unescapeJava(String str)
Unescapes any Java literals found in the String. For example, it will turn a sequence of
'\' and 'n' into a newline character, unless the '\' is preceded by
another '\'.
str - the String to unescape, may be nullString, null if null string inputpublic static void unescapeJava(Writer out, String str) throws IOException
Unescapes any Java literals found in the String to a Writer.
For example, it will turn a sequence of '\' and 'n' into a newline character, unless
the '\' is preceded by another '\'.
A null string input has no effect.
out - the Writer used to output unescaped charactersstr - the String to unescape, may be nullIllegalArgumentException - if the Writer is nullIOException - if error occurs on underlying Writerpublic static String[] split(String str)
Splits the provided text into an array, using whitespace as the separator. Whitespace is defined by
Character.isWhitespace(char).
The separator is not included in the returned String array. Adjacent separators are treated as one separator. For more control over the split use the StrTokenizer class.
A null input String returns null.
StringUtils.split(null) = null
StringUtils.split("") = []
StringUtils.split("abc def") = ["abc", "def"]
StringUtils.split("abc def") = ["abc", "def"]
StringUtils.split(" abc ") = ["abc"]
str - the String to parse, may be nullnull if null String inputpublic static String[] split(String str, char separatorChar)
Splits the provided text into an array, separator specified. This is an alternative to using StringTokenizer.
The separator is not included in the returned String array. Adjacent separators are treated as one separator. For more control over the split use the StrTokenizer class.
A null input String returns null.
StringUtils.split(null, *) = null
StringUtils.split("", *) = []
StringUtils.split("a.b.c", '.') = ["a", "b", "c"]
StringUtils.split("a..b.c", '.') = ["a", "b", "c"]
StringUtils.split("a:b:c", '.') = ["a:b:c"]
StringUtils.split("a b c", ' ') = ["a", "b", "c"]
str - the String to parse, may be nullseparatorChar - the character used as the delimiternull if null String inputpublic static String[] split(String str, String separatorChars)
Splits the provided text into an array, separators specified. This is an alternative to using StringTokenizer.
The separator is not included in the returned String array. Adjacent separators are treated as one separator. For more control over the split use the StrTokenizer class.
A null input String returns null. A null separatorChars splits on
whitespace.
StringUtils.split(null, *) = null
StringUtils.split("", *) = []
StringUtils.split("abc def", null) = ["abc", "def"]
StringUtils.split("abc def", " ") = ["abc", "def"]
StringUtils.split("abc def", " ") = ["abc", "def"]
StringUtils.split("ab:cd:ef", ":") = ["ab", "cd", "ef"]
str - the String to parse, may be nullseparatorChars - the characters used as the delimiters, null splits on whitespacenull if null String inputpublic static String[] split(String str, String separatorChars, int max)
Splits the provided text into an array with a maximum length, separators specified.
The separator is not included in the returned String array. Adjacent separators are treated as one separator.
A null input String returns null. A null separatorChars splits on
whitespace.
If more than max delimited substrings are found, the last returned string includes all characters
after the first max - 1 returned strings (including separator characters).
StringUtils.split(null, *, *) = null
StringUtils.split("", *, *) = []
StringUtils.split("ab de fg", null, 0) = ["ab", "cd", "ef"]
StringUtils.split("ab de fg", null, 0) = ["ab", "cd", "ef"]
StringUtils.split("ab:cd:ef", ":", 0) = ["ab", "cd", "ef"]
StringUtils.split("ab:cd:ef", ":", 2) = ["ab", "cd:ef"]
str - the String to parse, may be nullseparatorChars - the characters used as the delimiters, null splits on whitespacemax - the maximum number of elements to include in the array. A zero or negative value implies no limitnull if null String inputpublic static String[] splitByWholeSeparator(String str, String separator)
Splits the provided text into an array, separator string specified.
The separator(s) will not be included in the returned String array. Adjacent separators are treated as one separator.
A null input String returns null. A null separator splits on whitespace.
StringUtils.splitByWholeSeparator(null, *) = null
StringUtils.splitByWholeSeparator("", *) = []
StringUtils.splitByWholeSeparator("ab de fg", null) = ["ab", "de", "fg"]
StringUtils.splitByWholeSeparator("ab de fg", null) = ["ab", "de", "fg"]
StringUtils.splitByWholeSeparator("ab:cd:ef", ":") = ["ab", "cd", "ef"]
StringUtils.splitByWholeSeparator("ab-!-cd-!-ef", "-!-") = ["ab", "cd", "ef"]
str - the String to parse, may be nullseparator - String containing the String to be used as a delimiter, null splits on whitespacenull if null String was inputpublic static String[] splitByWholeSeparator(String str, String separator, int max)
Splits the provided text into an array, separator string specified. Returns a maximum of max
substrings.
The separator(s) will not be included in the returned String array. Adjacent separators are treated as one separator.
A null input String returns null. A null separator splits on whitespace.
StringUtils.splitByWholeSeparator(null, *, *) = null
StringUtils.splitByWholeSeparator("", *, *) = []
StringUtils.splitByWholeSeparator("ab de fg", null, 0) = ["ab", "de", "fg"]
StringUtils.splitByWholeSeparator("ab de fg", null, 0) = ["ab", "de", "fg"]
StringUtils.splitByWholeSeparator("ab:cd:ef", ":", 2) = ["ab", "cd:ef"]
StringUtils.splitByWholeSeparator("ab-!-cd-!-ef", "-!-", 5) = ["ab", "cd", "ef"]
StringUtils.splitByWholeSeparator("ab-!-cd-!-ef", "-!-", 2) = ["ab", "cd-!-ef"]
str - the String to parse, may be nullseparator - String containing the String to be used as a delimiter, null splits on whitespacemax - the maximum number of elements to include in the returned array. A zero or negative value implies no
limit.null if null String was inputpublic static String[] splitByWholeSeparatorPreserveAllTokens(String str, String separator)
Splits the provided text into an array, separator string specified.
The separator is not included in the returned String array. Adjacent separators are treated as separators for empty tokens. For more control over the split use the StrTokenizer class.
A null input String returns null. A null separator splits on whitespace.
StringUtils.splitByWholeSeparatorPreserveAllTokens(null, *) = null
StringUtils.splitByWholeSeparatorPreserveAllTokens("", *) = []
StringUtils.splitByWholeSeparatorPreserveAllTokens("ab de fg", null) = ["ab", "de", "fg"]
StringUtils.splitByWholeSeparatorPreserveAllTokens("ab de fg", null) = ["ab", "", "", "de", "fg"]
StringUtils.splitByWholeSeparatorPreserveAllTokens("ab:cd:ef", ":") = ["ab", "cd", "ef"]
StringUtils.splitByWholeSeparatorPreserveAllTokens("ab-!-cd-!-ef", "-!-") = ["ab", "cd", "ef"]
str - the String to parse, may be nullseparator - String containing the String to be used as a delimiter, null splits on whitespacenull if null String was inputpublic static String[] splitByWholeSeparatorPreserveAllTokens(String str, String separator, int max)
Splits the provided text into an array, separator string specified. Returns a maximum of max
substrings.
The separator is not included in the returned String array. Adjacent separators are treated as separators for empty tokens. For more control over the split use the StrTokenizer class.
A null input String returns null. A null separator splits on whitespace.
StringUtils.splitByWholeSeparatorPreserveAllTokens(null, *, *) = null
StringUtils.splitByWholeSeparatorPreserveAllTokens("", *, *) = []
StringUtils.splitByWholeSeparatorPreserveAllTokens("ab de fg", null, 0) = ["ab", "de", "fg"]
StringUtils.splitByWholeSeparatorPreserveAllTokens("ab de fg", null, 0) = ["ab", "", "", "de", "fg"]
StringUtils.splitByWholeSeparatorPreserveAllTokens("ab:cd:ef", ":", 2) = ["ab", "cd:ef"]
StringUtils.splitByWholeSeparatorPreserveAllTokens("ab-!-cd-!-ef", "-!-", 5) = ["ab", "cd", "ef"]
StringUtils.splitByWholeSeparatorPreserveAllTokens("ab-!-cd-!-ef", "-!-", 2) = ["ab", "cd-!-ef"]
str - the String to parse, may be nullseparator - String containing the String to be used as a delimiter, null splits on whitespacemax - the maximum number of elements to include in the returned array. A zero or negative value implies no
limit.null if null String was inputpublic static String escapeBytes(byte[] input)
#escapeBytes(ByteString), but used for byte array.public static int toInt(String str)
Convert a String to an int, returning zero if the conversion fails.
If the string is null, zero is returned.
NumberUtils.toInt(null) = 0
NumberUtils.toInt("") = 0
NumberUtils.toInt("1") = 1
str - the string to convert, may be nullzero if conversion failspublic static int stringToInt(String str, int defaultValue)
toInt(String, int) This method will be removed in Commons Lang 3.0
Convert a String to an int, returning a default value if the conversion fails.
If the string is null, the default value is returned.
NumberUtils.stringToInt(null, 1) = 1
NumberUtils.stringToInt("", 1) = 1
NumberUtils.stringToInt("1", 0) = 1
str - the string to convert, may be nulldefaultValue - the default valuepublic static int toInt(String str, int defaultValue)
Convert a String to an int, returning a default value if the conversion fails.
If the string is null, the default value is returned.
NumberUtils.toInt(null, 1) = 1
NumberUtils.toInt("", 1) = 1
NumberUtils.toInt("1", 0) = 1
str - the string to convert, may be nulldefaultValue - the default valuepublic static long toLong(String str)
Convert a String to an long, returning a default value if the conversion fails.
If the string is null, the default value is returned.
NumberUtils.toLong(null) = 0
NumberUtils.toLong("") = 0
NumberUtils.toLong("1") = 1
str - the string to convert, may be nullpublic static long toLong(String str, long defaultValue)
Convert a String to an long, returning a default value if the conversion fails.
If the string is null, the default value is returned.
NumberUtils.toLong(null, 1) = 1
NumberUtils.toLong("", 1) = 1
NumberUtils.toLong("1", 0) = 1
str - the string to convert, may be nulldefaultValue - the default valuepublic static String trimToEmpty(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 is null.
The String is trimmed using String.trim().
Trim removes start and end characters <= 32.
To strip whitespace use #stripToEmpty(String).
StringUtils.trimToEmpty(null) = ""
StringUtils.trimToEmpty("") = ""
StringUtils.trimToEmpty(" ") = ""
StringUtils.trimToEmpty("abc") = "abc"
StringUtils.trimToEmpty(" abc ") = "abc"
str - the String to be trimmed, may be nullnull inputpublic static String uncapitalize(String str)
Uncapitalizes a String, changing the first character to lower case as
per Character.toLowerCase(int). No other characters are changed.
For a word based algorithm, see org.apache.commons.lang3.text.WordUtils#uncapitalize(String).
A null input String returns null.
StringUtils.uncapitalize(null) = null
StringUtils.uncapitalize("") = ""
StringUtils.uncapitalize("cat") = "cat"
StringUtils.uncapitalize("Cat") = "cat"
StringUtils.uncapitalize("CAT") = "cAT"
str - the String to uncapitalize, may be nullnull if null String inputorg.apache.commons.lang3.text.WordUtils#uncapitalize(String),
capitalize(String)public static String toLowerCase(String str)
str - the strpublic static boolean isEmpty(Object[] array)
Checks if an array of Objects is empty or null.
array - the array to testtrue if the array is empty or nullCopyright © 2022 Baidu, Inc.. All rights reserved.