Top Description Fields Constructors Methods
org.apache.commons.lang3

public Class StringUtils

extends Object
Class Inheritance
Imports
java.io.UnsupportedEncodingException, java.nio.CharBuffer, java.nio.charset.Charset, java.text.Normalizer, java.util.ArrayList, .Arrays, .Iterator, .List, .Locale, .Objects, .Set, java.util.function.Supplier, java.util.regex.Pattern, java.util.stream.Collectors, org.apache.commons.lang3.function.Suppliers, org.apache.commons.lang3.stream.LangCollectors, .Streams

Operations on String that are null safe.

The StringUtils class defines certain words related to String handling.

StringUtils handles null input Strings quietly. That is to say that a null input will return null. Where a boolean or int is being returned details vary by method.

A side effect of the null handling is that a NullPointerException should be considered a bug in StringUtils.

Methods in this class include sample code in their Javadoc comments to explain their operation. The symbol * is used to indicate any input including null.

#ThreadSafe#

Since
1.0
See Also
String

Field Summary

Modifier and TypeField and Description
public static final String
CR

A String for carriage return CR ("\r").

private static final int
DEFAULT_TTL

The default maximum depth at which recursive replacement will continue until no further search replacements are possible.

private static final String
ELLIPSIS3

This is a 3 character version of an ellipsis.

public static final String
EMPTY

The empty String "".

public static final int
INDEX_NOT_FOUND

Represents a failed index search.

public static final String
LF

A String for linefeed LF ("\n").

pack-priv static final String
NULL

The null String null.

private static final int
PAD_LIMIT

The maximum size to which the padding constant(s) can expand.

public static final String
SPACE

A String for a space character.

private static final Pattern

Constructor Summary

AccessConstructor and Description
public
StringUtils()
Deprecated TODO Make private in 4.0.

StringUtils instances should NOT be constructed in standard programming.

Method Summary

Modifier and TypeMethod and Description
public static String

Returns:

abbreviated String, null if null String input.
abbreviate
(final String
the String to check, may be null.
str
,
final int
maximum length of result String, must be at least 4.
maxWidth
)

Abbreviates a String using ellipses.

public static String

Returns:

abbreviated String, null if null String input.
abbreviate
(final String
the String to check, may be null.
str
,
final int
left edge of source String.
offset
,
final int
maximum length of result String, must be at least 4.
maxWidth
)

Abbreviates a String using ellipses.

public static String

Returns:

abbreviated String, null if null String input.
abbreviate
(final String
the String to check, may be null.
str
,
final String
the String used as replacement marker.
abbrevMarker
,
final int
maximum length of result String, must be at least abbrevMarker.length + 1.
maxWidth
)

Abbreviates a String using another given String as replacement marker.

public static String

Returns:

abbreviated String, null if null String input.
abbreviate
(final String
the String to check, may be null.
str
,
final String
the String used as replacement marker.
abbrevMarker
,
int
left edge of source String.
offset
,
final int
maximum length of result String, must be at least 4.
maxWidth
)

Abbreviates a String using a given replacement marker.

public static String

Returns:

the abbreviated String if the above criteria is met, or the original String supplied for abbreviation.
abbreviateMiddle
(final String
the String to abbreviate, may be null.
str
,
final String
the String to replace the middle characters with, may be null.
middle
,
final int
the length to abbreviate str to.
length
)

Abbreviates a String to the length passed, replacing the middle characters with the supplied replacement String.

public static String

Returns:

A new String if suffix was appended, the same string otherwise.
appendIfMissing
(final String
The string.
str
,
final CharSequence
The suffix to append to the end of the string.
suffix
,
final CharSequence...
Additional suffixes that are valid terminators.
suffixes
)

Appends the suffix to the end of the string if the string does not already end with any of the suffixes.

public static String

Returns:

A new String if suffix was appended, the same string otherwise.
appendIfMissingIgnoreCase
(final String
The string.
str
,
final CharSequence
The suffix to append to the end of the string.
suffix
,
final CharSequence...
Additional suffixes that are valid terminators.
suffixes
)

Appends the suffix to the end of the string if the string does not already end, case-insensitive, with any of the suffixes.

public static String

Returns:

the capitalized String, null if null String input.
capitalize
(final String
the String to capitalize, may be null.
str
)

Capitalizes a String changing the first character to title case as per Character#toTitleCase(int).

public static String

Returns:

centered String, null if null String input.
center
(final String
the String to center, may be null.
str
,
final int
the int size of new String, negative treated as zero.
size
)

Centers a String in a larger String of size size using the space character (' ').

public static String

Returns:

centered String, null if null String input.
center
(String
the String to center, may be null.
str
,
final int
the int size of new String, negative treated as zero.
size
,
final char
the character to pad the new String with.
padChar
)

Centers a String in a larger String of size size.

public static String

Returns:

centered String, null if null String input.
center
(String
the String to center, may be null.
str
,
final int
the int size of new String, negative treated as zero.
size
,
String
the String to pad the new String with, must not be null or empty.
padStr
)

Centers a String in a larger String of size size.

public static String

Returns:

String without newline, null if null String input.
chomp
(final String
the String to chomp a newline from, may be null.
str
)

Removes one newline from end of a String if it's there, otherwise leave it alone.

public static String

Returns:

String without trailing separator, null if null String input.
chomp
(final String
the String to chomp from, may be null.
str
,
final String
separator String, may be null.
separator
)
Deprecated This feature will be removed in Lang 4, use StringUtils#removeEnd(String, String) instead.

Removes separator from the end of str if it's there, otherwise leave it alone.

public static String

Returns:

String without last character, null if null String input.
chop
(final String
the String to chop last character from, may be null.
str
)

Removes the last character from a String.

public static int

Returns:

< 0, 0, > 0, if str1 is respectively less, equal or greater than str2.
compare
(final String
the String to compare from.
str1
,
final String
the String to compare to.
str2
)

Compares two Strings lexicographically, as per String#compareTo(String), returning :

  • int = 0, if str1 is equal to str2 (or both null)
  • int < 0, if str1 is less than str2
  • int > 0, if str1 is greater than str2
public static int

Returns:

< 0, 0, > 0, if str1 is respectively less, equal ou greater than str2.
compare
(final String
the String to compare from.
str1
,
final String
the String to compare to.
str2
,
final boolean
whether consider null value less than non-null value.
nullIsLess
)

Compares two Strings lexicographically, as per String#compareTo(String), returning :

  • int = 0, if str1 is equal to str2 (or both null)
  • int < 0, if str1 is less than str2
  • int > 0, if str1 is greater than str2
public static int

Returns:

< 0, 0, > 0, if str1 is respectively less, equal ou greater than str2, ignoring case differences.
compareIgnoreCase
(final String
the String to compare from.
str1
,
final String
the String to compare to.
str2
)

Compares two Strings lexicographically, ignoring case differences, as per String#compareToIgnoreCase(String), returning :

  • int = 0, if str1 is equal to str2 (or both null)
  • int < 0, if str1 is less than str2
  • int > 0, if str1 is greater than str2
public static int

Returns:

< 0, 0, > 0, if str1 is respectively less, equal ou greater than str2, ignoring case differences.
compareIgnoreCase
(final String
the String to compare from.
str1
,
final String
the String to compare to.
str2
,
final boolean
whether consider null value less than non-null value.
nullIsLess
)

Compares two Strings lexicographically, ignoring case differences, as per String#compareToIgnoreCase(String), returning :

  • int = 0, if str1 is equal to str2 (or both null)
  • int < 0, if str1 is less than str2
  • int > 0, if str1 is greater than str2
public static boolean

Returns:

true if the CharSequence contains the search CharSequence, false if not or null string input
contains
(final CharSequence
the CharSequence to check, may be null
seq
,
final CharSequence
the CharSequence to find, may be null
searchSeq
)

Tests if CharSequence contains a search CharSequence, handling null.

public static boolean

Returns:

true if the CharSequence contains the search character, false if not or null string input
contains
(final CharSequence
the CharSequence to check, may be null
seq
,
final int
the character to find
searchChar
)

Tests if CharSequence contains a search character, handling null.

public static boolean

Returns:

the true if any of the chars are found, false if no match or null input.
containsAny
(final CharSequence
the CharSequence to check, may be null.
cs
,
final char...
the chars to search for, may be null.
searchChars
)

Tests if the CharSequence contains any character in the given set of characters.

public static boolean

Returns:

the true if any of the chars are found, false if no match or null input.
containsAny
(final CharSequence
the CharSequence to check, may be null.
cs
,
final CharSequence
the chars to search for, may be null.
searchChars
)

Tests if the CharSequence contains any character in the given set of characters.

public static boolean

Returns:

true if any of the search CharSequences are found, false otherwise.
containsAny
(final CharSequence
The CharSequence to check, may be null.
cs
,
final CharSequence...
The array of CharSequences to search for, may be null. Individual CharSequences may be null as well.
searchCharSequences
)

Tests if the CharSequence contains any of the CharSequences in the given array.

public static boolean

Returns:

true if any of the search CharSequences are found, false otherwise
containsAnyIgnoreCase
(final CharSequence
The CharSequence to check, may be null.
cs
,
final CharSequence...
The array of CharSequences to search for, may be null. Individual CharSequences may be null as well.
searchCharSequences
)

Tests if the CharSequence contains any of the CharSequences in the given array, ignoring case.

public static boolean

Returns:

true if the CharSequence contains the search CharSequence irrespective of case or false if not or null string input.
containsIgnoreCase
(final CharSequence
the CharSequence to check, may be null.
str
,
final CharSequence
the CharSequence to find, may be null.
searchStr
)

Tests if CharSequence contains a search CharSequence irrespective of case, handling null.

public static boolean

Returns:

true if it contains none of the invalid chars, or is null.
containsNone
(final CharSequence
the CharSequence to check, may be null.
cs
,
final char...
an array of invalid chars, may be null.
searchChars
)

Tests that the CharSequence does not contain certain characters.

public static boolean

Returns:

true if it contains none of the invalid chars, or is null.
containsNone
(final CharSequence
the CharSequence to check, may be null.
cs
,
final String
a String of invalid chars, may be null.
invalidChars
)

Tests that the CharSequence does not contain certain characters.

public static boolean

Returns:

true if it only contains valid chars and is non-null.
containsOnly
(final CharSequence
the String to check, may be null.
cs
,
final char...
an array of valid chars, may be null.
valid
)

Tests if the CharSequence contains only certain characters.

public static boolean

Returns:

true if it only contains valid chars and is non-null.
containsOnly
(final CharSequence
the CharSequence to check, may be null.
cs
,
final String
a String of valid chars, may be null.
validChars
)

Tests if the CharSequence contains only certain characters.

public static boolean

Returns:

true if the CharSequence is not empty and contains at least 1 (breaking) whitespace character.
containsWhitespace
(final CharSequence
the CharSequence to check (may be null).
seq
)

Tests whether the given CharSequence contains any whitespace characters.

private static void
public static int

Returns:

the number of occurrences, 0 if the CharSequence is null.
countMatches
(final CharSequence
the CharSequence to check, may be null.
str
,
final char
the char to count.
ch
)

Counts how many times the char appears in the given string.

public static int

Returns:

the number of occurrences, 0 if either CharSequence is null.
countMatches
(final CharSequence
the CharSequence to check, may be null.
str
,
final CharSequence
the substring to count, may be null.
sub
)

Counts how many times the substring appears in the larger string.

public static <
the specific kind of CharSequence.
T extends CharSequence
>
T

Returns:

the passed in CharSequence, or the default.
defaultIfBlank
(final T
the CharSequence to check, may be null.
str
,
final T
the default CharSequence to return if str is blank (whitespaces, empty ("") or null); may be null.
defaultStr
)

Returns either the passed in CharSequence, or if the CharSequence is blank (whitespaces, empty ("") or null), the value of defaultStr.

public static <
the specific kind of CharSequence.
T extends CharSequence
>
T

Returns:

the passed in CharSequence, or the default.
defaultIfEmpty
(final T
the CharSequence to check, may be null.
str
,
final T
the default CharSequence to return if the input is empty ("") or null, may be null.
defaultStr
)

Returns either the passed in CharSequence, or if the CharSequence is empty or null, the value of defaultStr.

public static String

Returns:

the passed in String, or the empty String if it was null.
defaultString
(final String
the String to check, may be null.
str
)

Returns either the passed in String, or if the String is null, an empty String ("").

public static String

Returns:

the passed in String, or the default if it was null.
defaultString
(final String
the String to check, may be null.
str
,
final String
the default String to return if the input is null, may be null.
nullDefault
)

Returns either the given String, or if the String is null, nullDefault.

public static String

Returns:

the String without whitespaces, null if null String input.
deleteWhitespace
(final String
the String to delete whitespace from, may be null.
str
)

Deletes all whitespaces from a String as defined by Character#isWhitespace(char).

public static String

Returns:

the portion of str2 where it differs from str1; returns the empty String if they are equal.
difference
(final String
the first String, may be null.
str1
,
final String
the second String, may be null.
str2
)

Compares two Strings, and returns the portion where they differ.

public static boolean

Returns:

true if the CharSequence ends with the suffix, case-sensitive, or both null.
endsWith
(final CharSequence
the CharSequence to check, may be null.
str
,
final CharSequence
the suffix to find, may be null.
suffix
)

Tests if a CharSequence ends with a specified suffix.

public static boolean

Returns:

true if the input sequence is null AND no searchStrings are provided, or the input sequence ends in any of the provided case-sensitive searchStrings.
endsWithAny
(final CharSequence
the CharSequence to check, may be null.
sequence
,
final CharSequence...
the case-sensitive CharSequences to find, may be empty or contain null.
searchStrings
)

Tests if a CharSequence ends with any of the provided case-sensitive suffixes.

public static boolean

Returns:

true if the CharSequence ends with the suffix, case-insensitive, or both null
endsWithIgnoreCase
(final CharSequence
the CharSequence to check, may be null
str
,
final CharSequence
the suffix to find, may be null
suffix
)

Case-insensitive check if a CharSequence ends with a specified suffix.

public static boolean

Returns:

true if the CharSequences are equal (case-sensitive), or both null.
equals
(final CharSequence
the first CharSequence, may be null.
cs1
,
final CharSequence
the second CharSequence, may be null.
cs2
)

Compares two CharSequences, returning true if they represent equal sequences of characters.

public static boolean

Returns:

true if the string is equal (case-sensitive) to any other element of searchStrings; false if searchStrings is null or contains no matches.
equalsAny
(final CharSequence
to compare, may be null.
string
,
final CharSequence...
a vararg of strings, may be null.
searchStrings
)

Compares given string to a CharSequences vararg of searchStrings, returning true if the string is equal to any of the searchStrings.

public static boolean

Returns:

true if the string is equal (case-insensitive) to any other element of searchStrings; false if searchStrings is null or contains no matches.
equalsAnyIgnoreCase
(final CharSequence
to compare, may be null.
string
,
final CharSequence...
a vararg of strings, may be null.
searchStrings
)

Compares given string to a CharSequences vararg of searchStrings, returning true if the string is equal to any of the searchStrings, ignoring case.

public static boolean

Returns:

true if the CharSequences are equal (case-insensitive), or both null.
equalsIgnoreCase
(final CharSequence
the first CharSequence, may be null.
cs1
,
final CharSequence
the second CharSequence, may be null.
cs2
)

Compares two CharSequences, returning true if they represent equal sequences of characters, ignoring case.

public static <
the specific kind of CharSequence.
T extends CharSequence
>
T

Returns:

the first value from values which is not blank, or null if there are no non-blank values.
firstNonBlank
(final T...
the values to test, may be null or empty.
values
)

Returns the first value in the array which is not empty (""), null or whitespace only.

public static <
the specific kind of CharSequence.
T extends CharSequence
>
T

Returns:

the first value from values which is not empty, or null if there are no non-empty values.
firstNonEmpty
(final T...
the values to test, may be null or empty.
values
)

Returns the first value in the array which is not empty.

public static byte[]

Returns:

The empty byte[] if string is null, the result of String#getBytes(Charset) otherwise.
getBytes
(final String
input string.
string
,
final Charset
The Charset to encode the String. If null, then use the default Charset.
charset
)

Calls String#getBytes(Charset) in a null-safe manner.

public static byte[]

Returns:

The empty byte[] if string is null, the result of String#getBytes(String) otherwise.
getBytes
(final String
input string.
string
,
final String
The Charset name to encode the String. If null, then use the default Charset.
charset
)

Calls String#getBytes(String) in a null-safe manner.

public static String

Returns:

the initial sequence of characters that are common to all Strings in the array; empty String if the array is null, the elements are all null or if there is no common prefix.
getCommonPrefix
(final String...
array of String objects, entries may be null.
strs
)

Compares all Strings in an array and returns the initial sequence of characters that is common to all of them.

public static String

Returns:

String with only digits, or an empty ("") String if no digits found, or null String if str is null.
getDigits
(final String
the String to extract digits from, may be null.
str
)

Checks if a String str contains Unicode digits, if yes then concatenate all the digits in str and return it as a String.

public static int

Returns:

result score.
getFuzzyDistance
(final CharSequence
a full term that should be matched against, must not be null.
term
,
final CharSequence
the query that will be matched against a term, must not be null.
query
,
final Locale
This string matching logic is case-insensitive. A locale is necessary to normalize both Strings to lower case.
locale
)
Deprecated As of 3.6, use Apache Commons Text FuzzyScore instead.

Gets the Fuzzy Distance which indicates the similarity score between two Strings.

public static <
the specific kind of CharSequence.
T extends CharSequence
>
T

Returns:

the passed in CharSequence, or the default
getIfBlank
(final T
the CharSequence to check, may be null.
str
,
final Supplier<T>
the supplier of default CharSequence to return if the input is blank (whitespaces, empty ("") or null); may be null.
defaultSupplier
)

Returns either the passed in CharSequence, or if the CharSequence is blank (whitespaces, empty ("") or null), the value supplied by defaultStrSupplier.

public static <
the specific kind of CharSequence.
T extends CharSequence
>
T

Returns:

the passed in CharSequence, or the default.
getIfEmpty
(final T
the CharSequence to check, may be null.
str
,
final Supplier<T>
the supplier of default CharSequence to return if the input is empty ("") or null, may be null.
defaultSupplier
)

Returns either the passed in CharSequence, or if the CharSequence is empty or null, the value supplied by defaultStrSupplier.

public static double

Returns:

result distance.
getJaroWinklerDistance
(final CharSequence
the first String, must not be null.
first
,
final CharSequence
the second String, must not be null.
second
)
Deprecated As of 3.6, use Apache Commons Text JaroWinklerDistance instead.

Gets the Jaro Winkler Distance which indicates the similarity score between two Strings.

public static int

Returns:

result distance.
getLevenshteinDistance
(CharSequence
the first String, must not be null.
s
,
CharSequence
the second String, must not be null.
t
)
Deprecated As of 3.6, use Apache Commons Text LevenshteinDistance instead.

Gets the Levenshtein distance between two Strings.

public static int

Returns:

result distance, or -1 if the distance would be greater than the threshold.
getLevenshteinDistance
(CharSequence
the first String, must not be null.
s
,
CharSequence
the second String, must not be null.
t
,
final int
the target threshold, must not be negative.
threshold
)
Deprecated As of 3.6, use Apache Commons Text LevenshteinDistance instead.

Gets the Levenshtein distance between two Strings if it's less than or equal to a given threshold.

public static int

Returns:

the first index of the search CharSequence, -1 if no match or null string input.
indexOf
(final CharSequence
the CharSequence to check, may be null.
seq
,
final CharSequence
the CharSequence to find, may be null.
searchSeq
)

Finds the first index within a CharSequence, handling null.

public static int

Returns:

the first index of the search CharSequence (always ≥ startPos), -1 if no match or null string input.
indexOf
(final CharSequence
the CharSequence to check, may be null.
seq
,
final CharSequence
the CharSequence to find, may be null.
searchSeq
,
final int
the start position, negative treated as zero.
startPos
)

Finds the first index within a CharSequence, handling null.

public static int

Returns:

the first index of the search character, -1 if no match or null string input.
indexOf
(final CharSequence
the CharSequence to check, may be null.
seq
,
final int
the character to find.
searchChar
)

Returns the index within seq of the first occurrence of the specified character.

public static int

Returns:

the first index of the search character (always ≥ startPos), -1 if no match or null string input.
indexOf
(final CharSequence
the CharSequence to check, may be null.
seq
,
final int
the character to find.
searchChar
,
final int
the start position, negative treated as zero.
startPos
)

Returns the index within seq of the first occurrence of the specified character, starting the search at the specified index.

public static int

Returns:

the index of any of the chars, -1 if no match or null input.
indexOfAny
(final CharSequence
the CharSequence to check, may be null.
cs
,
final char...
the chars to search for, may be null.
searchChars
)

Search a CharSequence to find the first index of any character in the given set of characters.

public static int

Returns:

the first index of any of the searchStrs in str, -1 if no match.
indexOfAny
(final CharSequence
the CharSequence to check, may be null.
str
,
final CharSequence...
the CharSequences to search for, may be null.
searchStrs
)

Find the first index of any of a set of potential substrings.

public static int

Returns:

the index of any of the chars, -1 if no match or null input.
indexOfAny
(final CharSequence
the CharSequence to check, may be null.
cs
,
final int
Start searching the input cs at this index.
csStart
,
final char...
the chars to search for, may be null.
searchChars
)

Search a CharSequence to find the first index of any character in the given set of characters.

public static int

Returns:

the index of any of the chars, -1 if no match or null input.
indexOfAny
(final CharSequence
the CharSequence to check, may be null.
cs
,
final String
the chars to search for, may be null.
searchChars
)

Search a CharSequence to find the first index of any character in the given set of characters.

public static int

Returns:

the index of any of the chars, -1 if no match or null input.
indexOfAnyBut
(final CharSequence
the CharSequence to check, may be null.
cs
,
final char...
the chars to search for, may be null.
searchChars
)

Searches a CharSequence to find the first index of any character not in the given set of characters, i.e., find index i of first char in cs such that (cs.codePointAt(i) ∉ { x ∈ codepoints(searchChars) })

A null CharSequence will return -1.

public static int

Returns:

the index of any of the chars, -1 if no match or null input.
indexOfAnyBut
(final CharSequence
the CharSequence to check, may be null.
seq
,
final CharSequence
the chars to search for, may be null.
searchChars
)

Search a CharSequence to find the first index of any character not in the given set of characters, i.e., find index i of first char in seq such that (seq.codePointAt(i) ∉ { x ∈ codepoints(searchChars) })

A null CharSequence will return -1.

public static int

Returns:

the index where the strings begin to differ; -1 if they are all equal.
indexOfDifference
(final CharSequence...
array of CharSequences, entries may be null.
css
)

Compares all CharSequences in an array and returns the index at which the CharSequences begin to differ.

public static int

Returns:

the index where cs1 and cs2 begin to differ; -1 if they are equal.
indexOfDifference
(final CharSequence
the first CharSequence, may be null.
cs1
,
final CharSequence
the second CharSequence, may be null.
cs2
)

Compares two CharSequences, and returns the index at which the CharSequences begin to differ.

public static int

Returns:

the first index of the search CharSequence, -1 if no match or null string input.
indexOfIgnoreCase
(final CharSequence
the CharSequence to check, may be null.
str
,
final CharSequence
the CharSequence to find, may be null.
searchStr
)

Case in-sensitive find of the first index within a CharSequence.

public static int

Returns:

the first index of the search CharSequence (always ≥ startPos), -1 if no match or null string input.
indexOfIgnoreCase
(final CharSequence
the CharSequence to check, may be null.
str
,
final CharSequence
the CharSequence to find, may be null.
searchStr
,
final int
the start position, negative treated as zero.
startPos
)

Case in-sensitive find of the first index within a CharSequence from the specified position.

public static boolean

Returns:

true if all of the CharSequences are empty or null or whitespace only.
isAllBlank
(final CharSequence...
the CharSequences to check, may be null or empty.
css
)

Tests if all of the CharSequences are empty (""), null or whitespace only.

public static boolean

Returns:

true if all of the CharSequences are empty or null.
isAllEmpty
(final CharSequence...
the CharSequences to check, may be null or empty.
css
)

Tests if all of the CharSequences are empty ("") or null.

public static boolean

Returns:

true if only contains lowercase characters, and is non-null.
isAllLowerCase
(final CharSequence
the CharSequence to check, may be null.
cs
)

Tests if the CharSequence contains only lowercase characters.

public static boolean

Returns:

true if only contains uppercase characters, and is non-null.
isAllUpperCase
(final CharSequence
the CharSequence to check, may be null.
cs
)

Tests if the CharSequence contains only uppercase characters.

public static boolean

Returns:

true if only contains letters, and is non-null.
isAlpha
(final CharSequence
the CharSequence to check, may be null.
cs
)

Tests if the CharSequence contains only Unicode letters.

public static boolean

Returns:

true if only contains letters or digits, and is non-null.
isAlphanumeric
(final CharSequence
the CharSequence to check, may be null.
cs
)

Tests if the CharSequence contains only Unicode letters or digits.

public static boolean

Returns:

true if only contains letters, digits or space, and is non-null.
isAlphanumericSpace
(final CharSequence
the CharSequence to check, may be null.
cs
)

Tests if the CharSequence contains only Unicode letters, digits or space (' ').

public static boolean

Returns:

true if only contains letters and space, and is non-null.
isAlphaSpace
(final CharSequence
the CharSequence to check, may be null.
cs
)

Tests if the CharSequence contains only Unicode letters and space (' ').

public static boolean

Returns:

true if any of the CharSequences are blank (whitespaces, empty ("") or null).
isAnyBlank
(final CharSequence...
the CharSequences to check, may be null or empty.
css
)

Tests if any of the CharSequences are blank (whitespaces, empty ("") or null).

public static boolean

Returns:

true if any of the CharSequences are empty or null.
isAnyEmpty
(final CharSequence...
the CharSequences to check, may be null or empty.
css
)

Tests if any of the CharSequences are empty ("") or null.

public static boolean

Returns:

true if every character is in the range 32 through 126.
isAsciiPrintable
(final CharSequence
the CharSequence to check, may be null.
cs
)

Tests if the CharSequence contains only ASCII printable characters.

public static boolean

Returns:

true if the CharSequence is null, empty or whitespace only.
isBlank
(final CharSequence
the CharSequence to check, may be null.
cs
)

Tests if a CharSequence is empty (""), null, or contains only whitespace as defined by Character#isWhitespace(char).

public static boolean

Returns:

true if the CharSequence is empty or null.
isEmpty
(final CharSequence
the CharSequence to check, may be null.
cs
)

Tests if a CharSequence is empty ("") or null.

public static boolean

Returns:

true if the CharSequence contains both uppercase and lowercase characters.
isMixedCase
(final CharSequence
the CharSequence to check, may be null.
cs
)

Tests if the CharSequence contains mixed casing of both uppercase and lowercase characters.

public static boolean

Returns:

true if none of the CharSequences are empty or null or whitespace only.
isNoneBlank
(final CharSequence...
the CharSequences to check, may be null or empty.
css
)

Tests if none of the CharSequences are empty (""), null or whitespace only.

public static boolean

Returns:

true if none of the CharSequences are empty or null.
isNoneEmpty
(final CharSequence...
the CharSequences to check, may be null or empty.
css
)

Tests if none of the CharSequences are empty ("") or null.

public static boolean

Returns:

true if the CharSequence is not blank (whitespaces, empty ("") or null).
isNotBlank
(final CharSequence
the CharSequence to check, may be null.
cs
)

Tests if a CharSequence is not blank (whitespaces, empty ("") or null).

public static boolean

Returns:

true if the CharSequence is not empty and not null.
isNotEmpty
(final CharSequence
the CharSequence to check, may be null.
cs
)

Tests if a CharSequence is not empty ("") and not null.

public static boolean

Returns:

true if only contains digits, and is non-null.
isNumeric
(final CharSequence
the CharSequence to check, may be null.
cs
)

Tests if the CharSequence contains only Unicode digits.

public static boolean

Returns:

true if only contains digits or space, and is non-null.
isNumericSpace
(final CharSequence
the CharSequence to check, may be null.
cs
)

Tests if the CharSequence contains only Unicode digits or space (' ').

public static boolean

Returns:

true if only contains whitespace, and is non-null.
isWhitespace
(final CharSequence
the CharSequence to check, may be null.
cs
)

Tests if the CharSequence contains only whitespace.

public static String

Returns:

the joined String, null if null array input.
join
(final boolean[]
the array of values to join together, may be null.
array
,
final char
the separator character to use.
delimiter
)

Joins the elements of the provided array into a single String containing the provided list of elements.

public static String

Returns:

the joined String, null if null array input.
join
(final boolean[]
the array of values to join together, may be null.
array
,
final char
the separator character to use.
delimiter
,
final int
the first index to start joining from. It is an error to pass in a start index past the end of the array.
startIndex
,
final int
the index to stop joining from (exclusive). It is an error to pass in an end index past the end of the array.
endIndex
)

Joins the elements of the provided array into a single String containing the provided list of elements.

public static String

Returns:

the joined String, null if null array input.
join
(final byte[]
the array of values to join together, may be null.
array
,
final char
the separator character to use.
delimiter
)

Joins the elements of the provided array into a single String containing the provided list of elements.

public static String

Returns:

the joined String, null if null array input.
join
(final byte[]
the array of values to join together, may be null.
array
,
final char
the separator character to use.
delimiter
,
final int
the first index to start joining from. It is an error to pass in a start index past the end of the array.
startIndex
,
final int
the index to stop joining from (exclusive). It is an error to pass in an end index past the end of the array.
endIndex
)

Joins the elements of the provided array into a single String containing the provided list of elements.

public static String

Returns:

the joined String, null if null array input.
join
(final char[]
the array of values to join together, may be null.
array
,
final char
the separator character to use.
delimiter
)

Joins the elements of the provided array into a single String containing the provided list of elements.

public static String

Returns:

the joined String, null if null array input.
join
(final char[]
the array of values to join together, may be null.
array
,
final char
the separator character to use.
delimiter
,
final int
the first index to start joining from. It is an error to pass in a start index past the end of the array.
startIndex
,
final int
the index to stop joining from (exclusive). It is an error to pass in an end index past the end of the array.
endIndex
)

Joins the elements of the provided array into a single String containing the provided list of elements.

public static String

Returns:

the joined String, null if null array input.
join
(final double[]
the array of values to join together, may be null.
array
,
final char
the separator character to use.
delimiter
)

Joins the elements of the provided array into a single String containing the provided list of elements.

public static String

Returns:

the joined String, null if null array input.
join
(final double[]
the array of values to join together, may be null.
array
,
final char
the separator character to use.
delimiter
,
final int
the first index to start joining from. It is an error to pass in a start index past the end of the array.
startIndex
,
final int
the index to stop joining from (exclusive). It is an error to pass in an end index past the end of the array.
endIndex
)

Joins the elements of the provided array into a single String containing the provided list of elements.

public static String

Returns:

the joined String, null if null array input
join
(final float[]
the array of values to join together, may be null.
array
,
final char
the separator character to use.
delimiter
)

Joins the elements of the provided array into a single String containing the provided list of elements.

public static String

Returns:

the joined String, null if null array input.
join
(final float[]
the array of values to join together, may be null.
array
,
final char
the separator character to use.
delimiter
,
final int
the first index to start joining from. It is an error to pass in a start index past the end of the array.
startIndex
,
final int
the index to stop joining from (exclusive). It is an error to pass in an end index past the end of the array.
endIndex
)

Joins the elements of the provided array into a single String containing the provided list of elements.

public static String

Returns:

the joined String, null if null array input.
join
(final int[]
the array of values to join together, may be null.
array
,
final char
the separator character to use.
separator
)

Joins the elements of the provided array into a single String containing the provided list of elements.

public static String

Returns:

the joined String, null if null array input.
join
(final int[]
the array of values to join together, may be null.
array
,
final char
the separator character to use.
delimiter
,
final int
the first index to start joining from. It is an error to pass in a start index past the end of the array.
startIndex
,
final int
the index to stop joining from (exclusive). It is an error to pass in an end index past the end of the array.
endIndex
)

Joins the elements of the provided array into a single String containing the provided list of elements.

public static String

Returns:

the joined String, null if null iterator input.
join
(final Iterable<?>
the Iterable providing the values to join together, may be null.
iterable
,
final char
the separator character to use.
separator
)

Joins the elements of the provided Iterable into a single String containing the provided elements.

public static String

Returns:

the joined String, null if null iterator input.
join
(final Iterable<?>
the Iterable providing the values to join together, may be null.
iterable
,
final String
the separator character to use, null treated as "".
separator
)

Joins the elements of the provided Iterable into a single String containing the provided elements.

public static String

Returns:

the joined String, null if null iterator input.
join
(final Iterator<?>
the Iterator of values to join together, may be null.
iterator
,
final char
the separator character to use.
separator
)

Joins the elements of the provided Iterator into a single String containing the provided elements.

public static String

Returns:

the joined String, null if null iterator input.
join
(final Iterator<?>
the Iterator of values to join together, may be null.
iterator
,
final String
the separator character to use, null treated as "".
separator
)

Joins the elements of the provided Iterator into a single String containing the provided elements.

public static String

Returns:

the joined String, null if null list input.
join
(final List<?>
the List of values to join together, may be null.
list
,
final char
the separator character to use.
separator
,
final int
the first index to start joining from. It is an error to pass in a start index past the end of the list.
startIndex
,
final int
the index to stop joining from (exclusive). It is an error to pass in an end index past the end of the list.
endIndex
)

Joins the elements of the provided List into a single String containing the provided list of elements.

public static String

Returns:

the joined String, null if null list input.
join
(final List<?>
the List of values to join together, may be null.
list
,
final String
the separator character to use.
separator
,
final int
the first index to start joining from. It is an error to pass in a start index past the end of the list.
startIndex
,
final int
the index to stop joining from (exclusive). It is an error to pass in an end index past the end of the list.
endIndex
)

Joins the elements of the provided List into a single String containing the provided list of elements.

public static String

Returns:

the joined String, null if null array input.
join
(final long[]
the array of values to join together, may be null.
array
,
final char
the separator character to use.
separator
)

Joins the elements of the provided array into a single String containing the provided list of elements.

public static String

Returns:

the joined String, null if null array input.
join
(final long[]
the array of values to join together, may be null.
array
,
final char
the separator character to use.
delimiter
,
final int
the first index to start joining from. It is an error to pass in a start index past the end of the array.
startIndex
,
final int
the index to stop joining from (exclusive). It is an error to pass in an end index past the end of the array.
endIndex
)

Joins the elements of the provided array into a single String containing the provided list of elements.

public static String

Returns:

the joined String, null if null array input.
join
(final Object[]
the array of values to join together, may be null.
array
,
final char
the separator character to use.
delimiter
)

Joins the elements of the provided array into a single String containing the provided list of elements.

public static String

Returns:

the joined String, null if null array input.
join
(final Object[]
the array of values to join together, may be null.
array
,
final char
the separator character to use.
delimiter
,
final int
the first index to start joining from. It is an error to pass in a start index past the end of the array.
startIndex
,
final int
the index to stop joining from (exclusive). It is an error to pass in an end index past the end of the array.
endIndex
)

Joins the elements of the provided array into a single String containing the provided list of elements.

public static String

Returns:

the joined String, null if null array input.
join
(final Object[]
the array of values to join together, may be null.
array
,
final String
the separator character to use, null treated as "".
delimiter
)

Joins the elements of the provided array into a single String containing the provided list of elements.

public static String

Returns:

the joined String, null if null array input; or the empty string if endIndex - startIndex <= 0. The number of joined entries is given by endIndex - startIndex.
join
(final Object[]
the array of values to join together, may be null.
array
,
final String
the separator character to use, null treated as "".
delimiter
,
final int
the first index to start joining from.
startIndex
,
final int
the index to stop joining from (exclusive).
endIndex
)

Joins the elements of the provided array into a single String containing the provided list of elements.

public static String

Returns:

the joined String, null if null array input.
join
(final short[]
the array of values to join together, may be null.
array
,
final char
the separator character to use.
delimiter
)

Joins the elements of the provided array into a single String containing the provided list of elements.

public static String

Returns:

the joined String, null if null array input.
join
(final short[]
the array of values to join together, may be null.
array
,
final char
the separator character to use.
delimiter
,
final int
the first index to start joining from. It is an error to pass in a start index past the end of the array.
startIndex
,
final int
the index to stop joining from (exclusive). It is an error to pass in an end index past the end of the array.
endIndex
)

Joins the elements of the provided array into a single String containing the provided list of elements.

public static <
the specific type of values to join together.
T
>
String

Returns:

the joined String, null if null array input.
join
(final T...
the values to join together, may be null.
elements
)

Joins the elements of the provided array into a single String containing the provided list of elements.

public static String

Returns:

the joined String.
joinWith
(final String
the separator character to use, null treated as "".
delimiter
,
final Object...
the varargs providing the values to join together. null elements are treated as "".
array
)

Joins the elements of the provided varargs into a single String containing the provided elements.

public static int

Returns:

the last index of the search String, -1 if no match or null string input.
lastIndexOf
(final CharSequence
the CharSequence to check, may be null.
seq
,
final CharSequence
the CharSequence to find, may be null.
searchSeq
)

Finds the last index within a CharSequence, handling null.

public static int

Returns:

the last index of the search CharSequence (always ≤ startPos), -1 if no match or null string input.
lastIndexOf
(final CharSequence
the CharSequence to check, may be null.
seq
,
final CharSequence
the CharSequence to find, may be null.
searchSeq
,
final int
the start position, negative treated as zero.
startPos
)

Finds the last index within a CharSequence, handling null.

public static int

Returns:

the last index of the search character, -1 if no match or null string input.
lastIndexOf
(final CharSequence
the CharSequence to check, may be null.
seq
,
final int
the character to find.
searchChar
)

Returns the index within seq of the last occurrence of the specified character.

public static int

Returns:

the last index of the search character (always ≤ startPos), -1 if no match or null string input.
lastIndexOf
(final CharSequence
the CharSequence to check, may be null.
seq
,
final int
the character to find.
searchChar
,
final int
the start position.
startPos
)

Returns the index within seq of the last occurrence of the specified character, searching backward starting at the specified index.

public static int

Returns:

the last index of any of the CharSequences, -1 if no match.
lastIndexOfAny
(final CharSequence
the CharSequence to check, may be null.
str
,
final CharSequence...
the CharSequences to search for, may be null.
searchStrs
)

Finds the latest index of any substring in a set of potential substrings.

public static int

Returns:

the first index of the search CharSequence, -1 if no match or null string input.
lastIndexOfIgnoreCase
(final CharSequence
the CharSequence to check, may be null.
str
,
final CharSequence
the CharSequence to find, may be null.
searchStr
)

Case in-sensitive find of the last index within a CharSequence.

public static int

Returns:

the last index of the search CharSequence (always ≤ startPos), -1 if no match or null input.
lastIndexOfIgnoreCase
(final CharSequence
the CharSequence to check, may be null.
str
,
final CharSequence
the CharSequence to find, may be null.
searchStr
,
final int
the start position.
startPos
)

Case in-sensitive find of the last index within a CharSequence from the specified position.

public static int

Returns:

the n-th last index of the search CharSequence, -1 (INDEX_NOT_FOUND) if no match or null string input.
lastOrdinalIndexOf
(final CharSequence
the CharSequence to check, may be null.
str
,
final CharSequence
the CharSequence to find, may be null.
searchStr
,
final int
the n-th last searchStr to find.
ordinal
)

Finds the n-th last index within a String, handling null.

public static String

Returns:

the leftmost characters, null if null String input.
left
(final String
the String to get the leftmost characters from, may be null.
str
,
final int
the length of the required String.
len
)

Gets the leftmost len characters of a String.

public static String

Returns:

left padded String or original String if no padding is necessary, null if null String input.
leftPad
(final String
the String to pad out, may be null.
str
,
final int
the size to pad to.
size
)

Left pad a String with spaces (' ').

public static String

Returns:

left padded String or original String if no padding is necessary, null if null String input.
leftPad
(final String
the String to pad out, may be null.
str
,
final int
the size to pad to.
size
,
final char
the character to pad with.
padChar
)

Left pad a String with a specified character.

public static String

Returns:

left padded String or original String if no padding is necessary, null if null String input.
leftPad
(final String
the String to pad out, may be null.
str
,
final int
the size to pad to.
size
,
String
the String to pad with, null or empty treated as single space.
padStr
)

Left pad a String with a specified String.

public static int

Returns:

CharSequence length or 0 if the CharSequence is null.
length
(final CharSequence
a CharSequence or null.
cs
)

Gets a CharSequence length or 0 if the CharSequence is null.

public static String

Returns:

the lower cased String, null if null String input.
lowerCase
(final String
the String to lower case, may be null.
str
)

Converts a String to lower case as per String#toLowerCase().

public static String

Returns:

the lower cased String, null if null String input.
lowerCase
(final String
the String to lower case, may be null.
str
,
final Locale
the locale that defines the case transformation rules, must not be null.
locale
)

Converts a String to lower case as per String#toLowerCase(Locale).

private static int[]
matches(final CharSequence first, final CharSequence second)

public static String

Returns:

the middle characters, null if null String input.
mid
(final String
the String to get the characters from, may be null.
str
,
int
the position to start from, negative treated as zero.
pos
,
final int
the length of the required String.
len
)

Gets len characters from the middle of a String.

public static String

Returns:

the modified string with whitespace normalized, null if null String input.
normalizeSpace
(final String
the source String to normalize whitespaces from, may be null.
str
)

Similar to https://www.w3.org/TR/xpath/#function-normalize -space

The function returns the argument string with whitespace normalized by using {@link #trim(String)} to remove leading and trailing whitespace and then replacing sequences of whitespace characters by a single space.

public static int

Returns:

the n-th index of the search CharSequence, -1 (INDEX_NOT_FOUND) if no match or null string input.
ordinalIndexOf
(final CharSequence
the CharSequence to check, may be null.
str
,
final CharSequence
the CharSequence to find, may be null.
searchStr
,
final int
the n-th searchStr to find.
ordinal
)

Finds the n-th index within a CharSequence, handling null.

private static int

Returns:

the n-th index of the search CharSequence, -1 (INDEX_NOT_FOUND) if no match or null string input.
ordinalIndexOf
(final CharSequence
the CharSequence to check, may be null.
str
,
final CharSequence
the CharSequence to find, may be null.
searchStr
,
final int
the n-th searchStr to find, overlapping matches are allowed.
ordinal
,
final boolean
true if lastOrdinalIndexOf() otherwise false if ordinalIndexOf().
lastIndex
)

Finds the n-th index within a String, handling null.

public static String

Returns:

overlayed String, null if null String input.
overlay
(final String
the String to do overlaying in, may be null.
str
,
String
the String to overlay, may be null.
overlay
,
int
the position to start overlaying at.
start
,
int
the position to stop overlaying before.
end
)

Overlays part of a String with another String.

public static String

Returns:

A new String if prefix was prepended, the same string otherwise.
prependIfMissing
(final String
The string.
str
,
final CharSequence
The prefix to prepend to the start of the string.
prefix
,
final CharSequence...
Additional prefixes that are valid.
prefixes
)

Prepends the prefix to the start of the string if the string does not already start with any of the prefixes.

public static String

Returns:

A new String if prefix was prepended, the same string otherwise.
prependIfMissingIgnoreCase
(final String
The string.
str
,
final CharSequence
The prefix to prepend to the start of the string.
prefix
,
final CharSequence...
Additional prefixes that are valid (optional).
prefixes
)

Prepends the prefix to the start of the string if the string does not already start, case-insensitive, with any of the prefixes.

public static String

Returns:

the substring with the char removed if found, null if null String input.
remove
(final String
the source String to search, may be null.
str
,
final char
the char to search for and remove, may be null.
remove
)

Removes all occurrences of a character from within the source string.

public static String

Returns:

the substring with the string removed if found, null if null String input.
remove
(final String
the source String to search, may be null.
str
,
final String
the String to search for and remove, may be null.
remove
)

Removes all occurrences of a substring from within the source string.

public static String

Returns:

the text with any removes processed, null if null String input.
removeAll
(final String
text to remove from, may be null.
text
,
final String
the regular expression to which this string is to be matched.
regex
)

Removes each substring of the text String that matches the given regular expression.

public static String

Returns:

the substring with the string removed if found, null if null String input.
removeEnd
(final String
the source String to search, may be null.
str
,
final String
the String to search for and remove, may be null.
remove
)

Removes a substring only if it is at the end of a source string, otherwise returns the source string.

public static String

Returns:

the substring with the string removed if found, null if null String input.
removeEndIgnoreCase
(final String
the source String to search, may be null.
str
,
final String
the String to search for (case-insensitive) and remove, may be null.
remove
)

Case-insensitive removal of a substring if it is at the end of a source string, otherwise returns the source string.

public static String

Returns:

the text with the first replacement processed, null if null String input.
removeFirst
(final String
text to remove from, may be null.
text
,
final String
the regular expression to which this string is to be matched.
regex
)

Removes the first substring of the text string that matches the given regular expression.

public static String

Returns:

the substring with the string removed if found, null if null String input.
removeIgnoreCase
(final String
the source String to search, may be null.
str
,
final String
the String to search for (case-insensitive) and remove, may be null.
remove
)

Case-insensitive removal of all occurrences of a substring from within the source string.

public static String

Returns:

The resulting String.
removePattern
(final String
the source string.
source
,
final String
the regular expression to which this string is to be matched.
regex
)

Removes each substring of the source String that matches the given regular expression using the DOTALL option.

public static String

Returns:

the substring with the char removed if found, null if null String input.
removeStart
(final String
the source String to search, may be null.
str
,
final char
the char to search for and remove.
remove
)

Removes a char only if it is at the beginning of a source string, otherwise returns the source string.

public static String

Returns:

the substring with the string removed if found, null if null String input.
removeStart
(final String
the source String to search, may be null.
str
,
final String
the String to search for and remove, may be null.
remove
)

Removes a substring only if it is at the beginning of a source string, otherwise returns the source string.

public static String

Returns:

the substring with the string removed if found, null if null String input.
removeStartIgnoreCase
(final String
the source String to search, may be null.
str
,
final String
the String to search for (case-insensitive) and remove, may be null.
remove
)

Case-insensitive removal of a substring if it is at the beginning of a source string, otherwise returns the source string.

public static String

Returns:

String with repeated character.
repeat
(final char
character to repeat.
repeat
,
final int
number of times to repeat char, negative treated as zero.
count
)

Returns padding using the specified delimiter repeated to a given length.

public static String

Returns:

a new String consisting of the original String repeated, null if null String input.
repeat
(final String
the String to repeat, may be null.
repeat
,
final int
number of times to repeat str, negative treated as zero.
count
)

Repeats a String repeat times to form a new String.

public static String

Returns:

a new String consisting of the original String repeated, null if null String input.
repeat
(final String
the String to repeat, may be null.
repeat
,
final String
the String to inject, may be null.
separator
,
final int
number of times to repeat str, negative treated as zero.
count
)

Repeats a String repeat times to form a new String, with a String separator injected each time.

public static String

Returns:

the text with any replacements processed, null if null String input.
replace
(final String
text to search and replace in, may be null.
text
,
final String
the String to search for, may be null.
searchString
,
final String
the String to replace it with, may be null.
replacement
)

Replaces all occurrences of a String within another String.

public static String

Returns:

the text with any replacements processed, null if null String input.
replace
(final String
text to search and replace in, may be null.
text
,
final String
the String to search for, may be null.
searchString
,
final String
the String to replace it with, may be null.
replacement
,
final int
maximum number of values to replace, or -1 if no maximum.
max
)

Replaces a String with another String inside a larger String, for the first max values of the search String.

public static String

Returns:

the text with any replacements processed, null if null String input.
replaceAll
(final String
text to search and replace in, may be null.
text
,
final String
the regular expression to which this string is to be matched.
regex
,
final String
the string to be substituted for each match.
replacement
)

Replaces each substring of the text String that matches the given regular expression with the given replacement.

public static String

Returns:

modified String, null if null string input.
replaceChars
(final String
String to replace characters in, may be null.
str
,
final char
the character to search for, may be null.
searchChar
,
final char
the character to replace, may be null.
replaceChar
)

Replaces all occurrences of a character in a String with another.

public static String

Returns:

modified String, null if null string input.
replaceChars
(final String
String to replace characters in, may be null.
str
,
final String
a set of characters to search for, may be null.
searchChars
,
String
a set of characters to replace, may be null.
replaceChars
)

Replaces multiple characters in a String in one go.

public static String

Returns:

the text with any replacements processed, null if null String input.
replaceEach
(final String
text to search and replace in, no-op if null.
text
,
final String[]
the Strings to search for, no-op if null.
searchList
,
final String[]
the Strings to replace them with, no-op if null.
replacementList
)

Replaces all occurrences of Strings within another String.

private static String

Returns:

the text with any replacements processed, null if null String input.
replaceEach
(final String
text to search and replace in, no-op if null.
text
,
final String[]
the Strings to search for, no-op if null.
searchList
,
final String[]
the Strings to replace them with, no-op if null.
replacementList
,
final boolean
if true, then replace repeatedly until there are no more possible replacements or timeToLive < 0.
repeat
,
final int
if less than 0 then there is a circular reference and endless loop.
timeToLive
)

Replace all occurrences of Strings within another String.

public static String

Returns:

the text with any replacements processed, null if null String input.
replaceEachRepeatedly
(final String
text to search and replace in, no-op if null.
text
,
final String[]
the Strings to search for, no-op if null.
searchList
,
final String[]
the Strings to replace them with, no-op if null.
replacementList
)

Replaces all occurrences of Strings within another String.

public static String

Returns:

the text with the first replacement processed, null if null String input.
replaceFirst
(final String
text to search and replace in, may be null.
text
,
final String
the regular expression to which this string is to be matched.
regex
,
final String
the string to be substituted for the first match.
replacement
)

Replaces the first substring of the text string that matches the given regular expression with the given replacement.

public static String

Returns:

the text with any replacements processed, null if null String input.
replaceIgnoreCase
(final String
text to search and replace in, may be null.
text
,
final String
the String to search for (case-insensitive), may be null.
searchString
,
final String
the String to replace it with, may be null.
replacement
)

Case insensitively replaces all occurrences of a String within another String.

public static String

Returns:

the text with any replacements processed, null if null String input.
replaceIgnoreCase
(final String
text to search and replace in, may be null.
text
,
final String
the String to search for (case-insensitive), may be null.
searchString
,
final String
the String to replace it with, may be null.
replacement
,
final int
maximum number of values to replace, or -1 if no maximum.
max
)

Case insensitively replaces a String with another String inside a larger String, for the first max values of the search String.

public static String

Returns:

the text with any replacements processed, null if null String input.
replaceOnce
(final String
text to search and replace in, may be null.
text
,
final String
the String to search for, may be null.
searchString
,
final String
the String to replace with, may be null.
replacement
)

Replaces a String with another String inside a larger String, once.

public static String

Returns:

the text with any replacements processed, null if null String input.
replaceOnceIgnoreCase
(final String
text to search and replace in, may be null.
text
,
final String
the String to search for (case-insensitive), may be null.
searchString
,
final String
the String to replace with, may be null.
replacement
)

Case insensitively replaces a String with another String inside a larger String, once.

public static String

Returns:

The resulting String.
replacePattern
(final String
the source string.
source
,
final String
the regular expression to which this string is to be matched.
regex
,
final String
the string to be substituted for each match.
replacement
)

Replaces each substring of the source String that matches the given regular expression with the given replacement using the Pattern#DOTALL option.

public static String

Returns:

the reversed String, null if null String input.
reverse
(final String
the String to reverse, may be null.
str
)

Reverses a String as per StringBuilder#reverse().

public static String

Returns:

the reversed String, null if null String input.
reverseDelimited
(final String
the String to reverse, may be null.
str
,
final char
the separator character to use.
separatorChar
)

Reverses a String that is delimited by a specific character.

public static String

Returns:

the rightmost characters, null if null String input.
right
(final String
the String to get the rightmost characters from, may be null.
str
,
final int
the length of the required String.
len
)

Gets the rightmost len characters of a String.

public static String

Returns:

right padded String or original String if no padding is necessary, null if null String input.
rightPad
(final String
the String to pad out, may be null.
str
,
final int
the size to pad to.
size
)

Right pad a String with spaces (' ').

public static String

Returns:

right padded String or original String if no padding is necessary, null if null String input.
rightPad
(final String
the String to pad out, may be null.
str
,
final int
the size to pad to.
size
,
final char
the character to pad with.
padChar
)

Right pad a String with a specified character.

public static String

Returns:

right padded String or original String if no padding is necessary, null if null String input.
rightPad
(final String
the String to pad out, may be null.
str
,
final int
the size to pad to.
size
,
String
the String to pad with, null or empty treated as single space.
padStr
)

Right pad a String with a specified String.

public static String

Returns:

the rotated String, or the original String if shift == 0, or null if null String input.
rotate
(final String
the String to rotate, may be null.
str
,
final int
number of time to shift (positive : right shift, negative : left shift).
shift
)

Rotate (circular shift) a String of shift characters.

public static String[]

Returns:

an array of parsed Strings, null if null String input.
split
(final String
the String to parse, may be null.
str
)

Splits the provided text into an array, using whitespace as the separator.

public static String[]

Returns:

an array of parsed Strings, null if null String input.
split
(final String
the String to parse, may be null.
str
,
final char
the character used as the delimiter.
separatorChar
)

Splits the provided text into an array, separator specified.

public static String[]

Returns:

an array of parsed Strings, null if null String input.
split
(final String
the String to parse, may be null.
str
,
final String
the characters used as the delimiters, null splits on whitespace.
separatorChars
)

Splits the provided text into an array, separators specified.

public static String[]

Returns:

an array of parsed Strings, null if null String input.
split
(final String
the String to parse, may be null.
str
,
final String
the characters used as the delimiters, null splits on whitespace.
separatorChars
,
final int
the maximum number of elements to include in the array. A zero or negative value implies no limit.
max
)

Splits the provided text into an array with a maximum length, separators specified.

public static String[]

Returns:

an array of parsed Strings, null if null String input.
splitByCharacterType
(final String
the String to split, may be null.
str
)

Splits a String by Character type as returned by java.lang.Character.getType(char).

private static String[]

Returns:

an array of parsed Strings, null if null String input.
splitByCharacterType
(final String
the String to split, may be null.
str
,
final boolean
whether to use so-called "camel-case" for letter types.
camelCase
)

Splits a String by Character type as returned by java.lang.Character.getType(char).

public static String[]

Returns:

an array of parsed Strings, null if null String input.
splitByCharacterTypeCamelCase
(final String
the String to split, may be null.
str
)

Splits a String by Character type as returned by java.lang.Character.getType(char).

public static String[]

Returns:

an array of parsed Strings, null if null String was input.
splitByWholeSeparator
(final String
the String to parse, may be null.
str
,
final String
String containing the String to be used as a delimiter, null splits on whitespace.
separator
)

Splits the provided text into an array, separator string specified.

public static String[]

Returns:

an array of parsed Strings, null if null String was input.
splitByWholeSeparator
(final String
the String to parse, may be null.
str
,
final String
String containing the String to be used as a delimiter, null splits on whitespace.
separator
,
final int
the maximum number of elements to include in the returned array. A zero or negative value implies no limit.
max
)

Splits the provided text into an array, separator string specified.

public static String[]

Returns:

an array of parsed Strings, null if null String was input.
splitByWholeSeparatorPreserveAllTokens
(final String
the String to parse, may be null.
str
,
final String
String containing the String to be used as a delimiter, null splits on whitespace.
separator
)

Splits the provided text into an array, separator string specified.

public static String[]

Returns:

an array of parsed Strings, null if null String was input.
splitByWholeSeparatorPreserveAllTokens
(final String
the String to parse, may be null.
str
,
final String
String containing the String to be used as a delimiter, null splits on whitespace.
separator
,
final int
the maximum number of elements to include in the returned array. A zero or negative value implies no limit.
max
)

Splits the provided text into an array, separator string specified.

private static String[]

Returns:

an array of parsed Strings, null if null String input.
splitByWholeSeparatorWorker
(final String
the String to parse, may be null.
str
,
final String
String containing the String to be used as a delimiter, null splits on whitespace.
separator
,
final int
the maximum number of elements to include in the returned array. A zero or negative value implies no limit.
max
,
final boolean
if true, adjacent separators are treated as empty token separators; if false, adjacent separators are treated as one separator.
preserveAllTokens
)

Performs the logic for the splitByWholeSeparatorPreserveAllTokens methods.

public static String[]

Returns:

an array of parsed Strings, null if null String input.
splitPreserveAllTokens
(final String
the String to parse, may be null.
str
)

Splits the provided text into an array, using whitespace as the separator, preserving all tokens, including empty tokens created by adjacent separators.

public static String[]

Returns:

an array of parsed Strings, null if null String input.
splitPreserveAllTokens
(final String
the String to parse, may be null.
str
,
final char
the character used as the delimiter, null splits on whitespace.
separatorChar
)

Splits the provided text into an array, separator specified, preserving all tokens, including empty tokens created by adjacent separators.

public static String[]

Returns:

an array of parsed Strings, null if null String input.
splitPreserveAllTokens
(final String
the String to parse, may be null.
str
,
final String
the characters used as the delimiters, null splits on whitespace.
separatorChars
)

Splits the provided text into an array, separators specified, preserving all tokens, including empty tokens created by adjacent separators.

public static String[]

Returns:

an array of parsed Strings, null if null String input.
splitPreserveAllTokens
(final String
the String to parse, may be null.
str
,
final String
the characters used as the delimiters, null splits on whitespace.
separatorChars
,
final int
the maximum number of elements to include in the array. A zero or negative value implies no limit.
max
)

Splits the provided text into an array with a maximum length, separators specified, preserving all tokens, including empty tokens created by adjacent separators.

private static String[]

Returns:

an array of parsed Strings, null if null String input.
splitWorker
(final String
the String to parse, may be null.
str
,
final char
the separate character.
separatorChar
,
final boolean
if true, adjacent separators are treated as empty token separators; if false, adjacent separators are treated as one separator.
preserveAllTokens
)

Performs the logic for the split and splitPreserveAllTokens methods that do not return a maximum array length.

private static String[]

Returns:

an array of parsed Strings, null if null String input.
splitWorker
(final String
the String to parse, may be null.
str
,
final String
the separate character.
separatorChars
,
final int
the maximum number of elements to include in the array. A zero or negative value implies no limit.
max
,
final boolean
if true, adjacent separators are treated as empty token separators; if false, adjacent separators are treated as one separator.
preserveAllTokens
)

Performs the logic for the split and splitPreserveAllTokens methods that return a maximum array length.

public static boolean

Returns:

true if the CharSequence starts with the prefix, case-sensitive, or both null.
startsWith
(final CharSequence
the CharSequence to check, may be null.
str
,
final CharSequence
the prefix to find, may be null.
prefix
)

Tests if a CharSequence starts with a specified prefix.

public static boolean

Returns:

true if the input sequence is null AND no searchStrings are provided, or the input sequence begins with any of the provided case-sensitive searchStrings.
startsWithAny
(final CharSequence
the CharSequence to check, may be null.
sequence
,
final CharSequence...
the case-sensitive CharSequence prefixes, may be empty or contain null.
searchStrings
)

Tests if a CharSequence starts with any of the provided case-sensitive prefixes.

public static boolean

Returns:

true if the CharSequence starts with the prefix, case-insensitive, or both null.
startsWithIgnoreCase
(final CharSequence
the CharSequence to check, may be null.
str
,
final CharSequence
the prefix to find, may be null.
prefix
)

Case-insensitive check if a CharSequence starts with a specified prefix.

public static String

Returns:

the stripped String, null if null String input.
strip
(final String
the String to remove whitespace from, may be null.
str
)

Strips whitespace from the start and end of a String.

public static String

Returns:

the stripped String, null if null String input.
strip
(String
the String to remove characters from, may be null.
str
,
final String
the characters to remove, null treated as whitespace.
stripChars
)

Strips any of a set of characters from the start and end of a String.

public static String

Returns:

input text with diacritics removed.
stripAccents
(final String
String to be stripped.
input
)

Removes diacritics (~= accents) from a string.

public static String[]

Returns:

the stripped Strings, null if null array input.
stripAll
(final String...
the array to remove whitespace from, may be null.
strs
)

Strips whitespace from the start and end of every String in an array.

public static String[]

Returns:

the stripped Strings, null if null array input.
stripAll
(final String[]
the array to remove characters from, may be null.
strs
,
final String
the characters to remove, null treated as whitespace.
stripChars
)

Strips any of a set of characters from the start and end of every String in an array.

public static String

Returns:

the stripped String, null if null String input.
stripEnd
(final String
the String to remove characters from, may be null.
str
,
final String
the set of characters to remove, null treated as whitespace.
stripChars
)

Strips any of a set of characters from the end of a String.

public static String

Returns:

the stripped String, null if null String input.
stripStart
(final String
the String to remove characters from, may be null.
str
,
final String
the characters to remove, null treated as whitespace.
stripChars
)

Strips any of a set of characters from the start of a String.

public static String

Returns:

the trimmed String, or an empty String if null input.
stripToEmpty
(final String
the String to be stripped, may be null.
str
)

Strips whitespace from the start and end of a String returning an empty String if null input.

public static String

Returns:

the stripped String, null if whitespace, empty or null String input.
stripToNull
(String
the String to be stripped, may be null.
str
)

Strips whitespace from the start and end of a String returning null if the String is empty ("") after the strip.

public static String

Returns:

substring from start position, null if null String input.
substring
(final String
the String to get the substring from, may be null.
str
,
int
the position to start from, negative means count back from the end of the String by this many characters.
start
)

Gets a substring from the specified String avoiding exceptions.

public static String

Returns:

substring from start position to end position, null if null String input.
substring
(final String
the String to get the substring from, may be null.
str
,
int
the position to start from, negative means count back from the end of the String by this many characters.
start
,
int
the position to end at (exclusive), negative means count back from the end of the String by this many characters.
end
)

Gets a substring from the specified String avoiding exceptions.

public static String

Returns:

the substring after the first occurrence of the specified character, null if null String input.
substringAfter
(final String
the String to get a substring from, may be null.
str
,
final int
the character (Unicode code point) to find.
find
)

Gets the substring after the first occurrence of a separator.

public static String

Returns:

the substring after the first occurrence of the specified string, null if null String input.
substringAfter
(final String
the String to get a substring from, may be null.
str
,
final String
the String to find, may be null.
find
)

Gets the substring after the first occurrence of a separator.

public static String

Returns:

the substring after the last occurrence of the specified character, null if null String input.
substringAfterLast
(final String
the String to get a substring from, may be null.
str
,
final int
the character (Unicode code point) to find.
find
)

Gets the substring after the last occurrence of a separator.

public static String

Returns:

the substring after the last occurrence of the specified string, null if null String input.
substringAfterLast
(final String
the String to get a substring from, may be null.
str
,
final String
the String to find, may be null.
find
)

Gets the substring after the last occurrence of a separator.

public static String

Returns:

the substring before the first occurrence of the specified character, null if null String input.
substringBefore
(final String
the String to get a substring from, may be null.
str
,
final int
the character (Unicode code point) to find.
find
)

Gets the substring before the first occurrence of a separator.

public static String

Returns:

the substring before the first occurrence of the specified string, null if null String input.
substringBefore
(final String
the String to get a substring from, may be null.
str
,
final String
the String to find, may be null.
find
)

Gets the substring before the first occurrence of a separator.

public static String

Returns:

the substring before the last occurrence of the specified string, null if null String input.
substringBeforeLast
(final String
the String to get a substring from, may be null.
str
,
final String
the String to find, may be null.
find
)

Gets the substring before the last occurrence of a separator.

public static String

Returns:

the substring, null if no match.
substringBetween
(final String
the String containing the substring, may be null.
str
,
final String
the String before and after the substring, may be null.
tag
)

Gets the String that is nested in between two instances of the same String.

public static String

Returns:

the substring, null if no match.
substringBetween
(final String
the String containing the substring, may be null.
str
,
final String
the String before the substring, may be null.
open
,
final String
the String after the substring, may be null.
close
)

Gets the String that is nested in between two Strings.

public static String[]

Returns:

a String Array of substrings, or null if no match.
substringsBetween
(final String
the String containing the substrings, null returns null, empty returns empty.
str
,
final String
the String identifying the start of the substring, empty returns null.
open
,
final String
the String identifying the end of the substring, empty returns null.
close
)

Searches a String for substrings delimited by a start and end tag, returning all matching substrings in an array.

public static String

Returns:

the changed String, null if null String input.
swapCase
(final String
the String to swap case, may be null.
str
)

Swaps the case of a String changing upper and title case to lower case, and lower case to upper case.

public static int[]

Returns:

an array of code points.
toCodePoints
(final CharSequence
the character sequence to convert.
cs
)

Converts a CharSequence into an array of code points.

public static String

Returns:

a new String.
toEncodedString
(final byte[]
the byte array to read from.
bytes
,
final Charset
the encoding to use, if null then use the platform default.
charset
)

Converts a byte[] to a String using the specified character encoding.

public static String

Returns:

the given source String as a lower-case using the Locale#ROOT locale or null.
toRootLowerCase
(final String
A source String or null.
source
)

Converts the given source String as a lower-case using the Locale#ROOT locale in a null-safe manner.

public static String

Returns:

the given source String as an upper-case using the Locale#ROOT locale or null.
toRootUpperCase
(final String
A source String or null.
source
)

Converts the given source String as an upper-case using the Locale#ROOT locale in a null-safe manner.

public static String

Returns:

a new String.
toString
(final byte[]
the byte array to read from.
bytes
,
final String
the encoding to use, if null then use the platform default.
charsetName
)
Deprecated Use StringUtils#toEncodedString(byte[], Charset) instead of String constants in your code.

Converts a byte[] to a String using the specified character encoding.

public static String

Returns:

the trimmed string, null if null String input.
trim
(final String
the String to be trimmed, may be null.
str
)

Removes control characters (char <= 32) from both ends of this String, handling null by returning null.

public static String

Returns:

the trimmed String, or an empty String if null input.
trimToEmpty
(final String
the String to be trimmed, may be null.
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.

public static String

Returns:

the trimmed String, null if only chars <= 32, empty or null String input.
trimToNull
(final String
the String to be trimmed, may be null.
str
)

Removes control characters (char <= 32) from both ends of this String returning null if the String is empty ("") after the trim or if it is null.

public static String

Returns:

truncated String, null if null String input.
truncate
(final String
the String to truncate, may be null.
str
,
final int
maximum length of result String, must be positive.
maxWidth
)

Truncates a String.

public static String

Returns:

truncated String, null if null String input.
truncate
(final String
the String to truncate, may be null.
str
,
final int
left edge of source String.
offset
,
final int
maximum length of result String, must be positive.
maxWidth
)

Truncates a String.

public static String

Returns:

the uncapitalized String, null if null String input.
uncapitalize
(final String
the String to uncapitalize, may be null.
str
)

Uncapitalizes a String, changing the first character to lower case as per Character#toLowerCase(int).

public static String

Returns:

unwrapped String or the original string if it is not quoted properly with the wrapChar.
unwrap
(final String
the String to be unwrapped, can be null.
str
,
final char
the character used to unwrap.
wrapChar
)

Unwraps a given string from a character.

public static String

Returns:

unwrapped String or the original string if it is not quoted properly with the wrapToken.
unwrap
(final String
the String to be unwrapped, can be null.
str
,
final String
the String used to unwrap.
wrapToken
)

Unwraps a given string from another string.

public static String

Returns:

the upper-cased String, null if null String input.
upperCase
(final String
the String to upper case, may be null.
str
)

Converts a String to upper case as per String#toUpperCase().

public static String

Returns:

the upper-cased String, null if null String input.
upperCase
(final String
the String to upper case, may be null.
str
,
final Locale
the locale that defines the case transformation rules, must not be null.
locale
)

Converts a String to upper case as per String#toUpperCase(Locale).

public static String

Returns:

a String or null.
valueOf
(final char[]
the character array.
value
)

Returns the string representation of the char array or null.

public static String

Returns:

the wrapped string, or null if str == null.
wrap
(final String
the string to be wrapped, may be null.
str
,
final char
the char that will wrap str.
wrapWith
)

Wraps a string with a char.

public static String

Returns:

wrapped String, null if null String input.
wrap
(final String
the String to be wrapper, may be null.
str
,
final String
the String that will wrap str.
wrapWith
)

Wraps a String with another String.

public static String

Returns:

the wrapped string, or null if str == null.
wrapIfMissing
(final String
the string to be wrapped, may be null.
str
,
final char
the char that will wrap str.
wrapWith
)

Wraps a string with a char if that char is missing from the start or end of the given string.

public static String

Returns:

the wrapped string, or null if str == null.
wrapIfMissing
(final String
the string to be wrapped, may be null.
str
,
final String
the string that will wrap str.
wrapWith
)

Wraps a string with a string if that string is missing from the start or end of the given string.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait