String utility methods.
Mainly for internal use within the framework; consider
Apache's Commons Lang
for a more comprehensive suite of String utilities.
This class delivers some simple functionality that should really be
provided by the core Java String and StringBuilder
classes. It also provides easy-to-use methods to convert between
delimited strings, such as CSV strings, and collections and arrays.
| Modifier and Type | Field and Description |
|---|---|
| private static final String | |
| private static final int | |
| private static final String[] | |
| private static final char | |
| private static final String | |
| private static final char | |
| private static final String | |
| private static final String | |
| private static final String |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public static String[] | Returns: the new array (nevernull)the array to append to (can be array, String null)the str)String to appendAppend the given |
| public static String | Returns: the full file path that results from applying the relative paththe path to start from (usually a full file path) path, String the relative path to apply
(relative to the full file path above) relativePath)Apply the given relative path to the given Java resource path, assuming standard Java folder separation (i.e. "/" separators). |
| public static String | Returns: the delimitedStringthe array to display (potentially arr)null or empty)Convert a |
| public static String | Returns: the delimitedStringthe array to display (potentially arr, String null or empty)the delimiter to use (typically a ",") delim)Convert a |
| public static String | Returns: the capitalizedStringthe str)String to capitalizeCapitalize a |
| private static String | |
| public static String | |
| public static String | Returns: the delimitedStringthe coll)Collection to convert (potentially null or empty)Convert a |
| public static String | Returns: the delimitedStringthe coll, String Collection to convert (potentially null or empty)the delimiter to use (typically a ",") delim, String the prefix, String String to start each element withthe suffix)String to end each element withConvert a |
| public static String | Returns: the delimitedStringthe coll, String Collection to convert (potentially null or empty)the delimiter to use (typically a ",") delim)Convert a |
| public static Set | Returns: a set ofString entries in the listthe input str)String (potentially null or empty)Convert a comma delimited list (e.g., a row from a CSV file) into a set. |
| public static String[] | Returns: an array of strings, or the empty array in case of empty inputthe input str)String (potentially null or empty)Convert a comma delimited list (e.g., a row from a CSV file) into an array of strings. |
| public static String[] | Returns: the new array (null if both given arrays were null)the first array (can be array1, String[] null)the second array (can be array2)null)Concatenate the given |
| public static boolean | Returns: true if the CharSequence is not empty and
contains at least 1 whitespace characterthe str)CharSequence to check (may be null)Check whether the given |
| public static boolean | Returns: true if the String is not empty and
contains at least 1 whitespace characterthe str)String to check (may be null)Check whether the given |
| public static int | countOccurrencesOf(String
string to search in str, String string to search for sub)Count the occurrences of the substring |
| public static String | |
| public static String | |
| public static String[] | Returns: an array of the tokens in the listthe input str, String String (potentially null or empty)the delimiter between elements (this is a single delimiter,
rather than a bunch individual delimiter characters) delimiter)Take a |
| public static String[] | Returns: an array of the tokens in the listthe input str, String String (potentially null or empty)the delimiter between elements (this is a single delimiter,
rather than a bunch individual delimiter characters) delimiter, String a set of characters to delete; useful for deleting unwanted
line breaks: e.g. "\r\n\f" will delete all new lines and line feeds in a charsToDelete)StringTake a |
| public static boolean | endsWithIgnoreCase(String
the str, String String to checkthe suffix to look for suffix)Test if the given |
| public static String | Returns: the extracted filename, ornull if nonethe file path (may be path)null)Extract the filename from the given Java resource path,
e.g. |
| public static String | Returns: the extracted filename extension, ornull if nonethe file path (may be path)null)Extract the filename extension from the given Java resource path, e.g. "mypath/myfile.txt" → "txt". |
| public static boolean | Returns: true if the CharSequence is not null and has lengththe str)CharSequence to check (may be null)Check that the given |
| public static boolean | |
| public static boolean | Returns: true if the CharSequence is not null,
its length is greater than 0, and it does not contain whitespace onlythe str)CharSequence to check (may be null)Check whether the given |
| public static boolean | |
| public static boolean | isEmpty(Object
the candidate object (possibly a str)String)
Deprecated
as of 5.3, in favor of
hasLength(String) and
hasText(String) (or ObjectUtils#isEmpty(Object))
Check whether the given object (possibly a |
| public static boolean | matchesCharacter(String
the str, char String to checkthe character to compare to singleCharacter)Test if the given |
| public static Locale | Returns: a correspondingLocale instance, or null if nonethe locale value: following either localeValue)Locale's
toString() format ("en", "en_UK", etc.), also accepting spaces as
separators (as an alternative to underscores), or BCP 47 (e.g. "en-UK")Parse the given |
| public static Locale | Returns: a correspondingLocale instance, or null if nonethe locale localeString)String: following Locale's
toString() format ("en", "en_UK", etc.), also accepting spaces as
separators (as an alternative to underscores)Parse the given |
| public static TimeZone | Returns: a correspondingTimeZone instancethe time zone timeZoneString)String, following TimeZone#getTimeZone(String)
but throwing IllegalArgumentException in case of an invalid time zone specificationParse the given |
| public static boolean | Returns: whether the two paths are equivalent after normalizationfirst path for comparison path1, String second path for comparison path2)Compare two paths after normalization of them. |
| public static String | |
| public static Object | Returns: the quotedString (e.g. "'myString'"),
or the input object as-is if not a Stringthe input Object (e.g. "myString") obj)Turn the given Object into a |
| public static String[] | Returns: an array without duplicates, in natural sort orderthe array)String array (potentially empty)Remove duplicate strings from the given array. |
| public static String | |
| public static String[] | Returns: the array in sorted form (nevernull)the original array (potentially empty) array)Sort the given |
| public static String[] | Returns: a two element array with index 0 being before the delimiter, and index 1 being after the delimiter (neither element includes the delimiter); ornull if the delimiter wasn't found in the given input Stringthe string to split (potentially toSplit, String null or empty)to split the string up with (potentially delimiter)null or empty)Split a |
| public static Properties | Returns: aProperties instance representing the array contents,
or null if the array to process was null or emptythe array to process array, String to split each element using (typically the equals symbol) delimiter)Take an array of strings and split each element based on the given delimiter. |
| public static Properties | Returns: aProperties instance representing the array contents,
or null if the array to process was null or emptythe array to process array, String to split each element using (typically the equals symbol) delimiter, String one or more characters to remove from each element
prior to attempting the split operation (typically the quotation mark
symbol), or charsToDelete)null if no removal should occurTake an array of strings and split each element based on the given delimiter. |
| public static boolean | startsWithIgnoreCase(String
the str, String String to checkthe prefix to look for prefix)Test if the given |
| public static String | Returns: the path with stripped filename extensionthe file path path)Strip the filename extension from the given Java resource path, e.g. "mypath/myfile.txt" → "mypath/myfile". |
| public static boolean | substringMatch(CharSequence
the original string (or StringBuilder) str, int the index in the original string to start matching against index, CharSequence the substring to match at the given index substring)Test whether the given string matches the given substring at the given index. |
| public static String[] | Returns: an array of the tokensthe str, String String to tokenize (potentially null or empty)the delimiter characters, assembled as a delimiters)String
(each of the characters is individually considered as a delimiter)Tokenize the given |
| public static String[] | Returns: an array of the tokensthe str, String String to tokenize (potentially null or empty)the delimiter characters, assembled as a delimiters, boolean String
(each of the characters is individually considered as a delimiter)trim the tokens via trimTokens, boolean String#trim()omit empty tokens from the result array
(only applies to tokens that are empty after trimming; StringTokenizer
will not consider subsequent delimiters as token in the first place). ignoreEmptyTokens)Tokenize the given |
| public static String[] | Returns: the resultingString arraythe collection)Collection to copy
(potentially null or empty)Copy the given |
| public static String[] | Returns: the resultingString arraythe enumeration)Enumeration to copy
(potentially null or empty)Copy the given |
| public static CharSequence | Returns: the trimmedCharSequencethe str)CharSequence to checkTrim all whitespace from the given |
| public static String | Returns: the trimmedStringthe str)String to checkTrim all whitespace from the given |
| public static String[] | Returns: the resulting array (of the same size) with trimmed elementsthe original array)String array (potentially empty)Trim the elements of the given |
| public static String | Returns: the trimmedStringthe str, char String to checkthe leading character to be trimmed leadingCharacter)Trim all occurrences of the supplied leading character from the given |
| public static String | Returns: the trimmedStringthe str)String to check
Deprecated
since 6.0. since 6.0, in favor of
String#stripLeading()
Trim leading whitespace from the given |
| public static String | Returns: the trimmedStringthe str, char String to checkthe trailing character to be trimmed trailingCharacter)Trim all occurrences of the supplied trailing character from the given |
| public static String | Returns: the trimmedStringthe str)String to check
Deprecated
since 6.0. since 6.0, in favor of
String#stripTrailing()
Trim trailing whitespace from the given |
| public static String | Returns: the trimmedStringthe str)String to check
Deprecated
since 6.0. since 6.0, in favor of
String#strip()
Trim leading and trailing whitespace from the given |
| public static String | Returns: a truncated string, or a string representation of the originalCharSequence if its length does not exceed the thresholdthe charSequence)CharSequence to truncateTruncate the supplied |
| public static String | Returns: a truncated string, or a string representation of the originalCharSequence if its length does not exceed the thresholdthe charSequence, int CharSequence to truncatethe maximum length after which to truncate; must be a
positive number threshold)Truncate the supplied |
| public static String | Returns: the uncapitalizedStringthe str)String to uncapitalizeUncapitalize a |
| public static String | Returns: the uncapitalizedStringthe str)String to uncapitalizeUncapitalize a |
| public static String | |
| public static String | |
| public static String | |
| private static void |