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

public abstract Class Strings

extends Object
Class Inheritance
Known Direct Subclasses
org.apache.commons.lang3.Strings.CiStrings, org.apache.commons.lang3.Strings.CsStrings
Static Imports
org.apache.commons.lang3.StringUtils.INDEX_NOT_FOUND

String operations where you choose case-sensitive CS vs. case-insensitive CI through a singleton instance.
Since
3.18.0
See Also
CharSequenceUtils, StringUtils

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
Strings.Builder

Builds Strings instances.

private static class
Strings.CiStrings

Case-insensitive extension.

private static class
Strings.CsStrings

Case-sentive extension.

Field Summary

Modifier and TypeField and Description
public static final Strings
CI

The Case-Insensitive singleton instance.

public static final Strings
CS

The Case-Sensitive singleton instance.

private final boolean
ignoreCase

Ignores case when possible.

private final boolean
nullIsLess

Compares null as less when possible.

Constructor Summary

AccessConstructor and Description
private
Strings(final boolean
Ignores case when possible.
ignoreCase
,
final boolean
Compares null as less when possible.
nullIsLess
)

Constructs a new instance.

Method Summary

Modifier and TypeMethod and Description
public 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 (optional).
suffixes
)

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

public static final Strings.Builder

Returns:

a new Builder instance.
builder
()

Constructs a new Builder instance.

public abstract int

Returns:

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

Compare two Strings lexicographically, like String#compareTo(String).

public abstract boolean

Returns:

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

Tests if CharSequence contains a search CharSequence, handling null.

private static boolean

Returns:

true if any of the search CharSequences are found, false otherwise
containsAny
(final ToBooleanBiFunction<CharSequence, CharSequence> test, 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 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 boolean

Returns:

true if the CharSequence starts with the prefix 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 boolean

Returns:

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

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

private static boolean
eq(final Object o1, final Object o2)

Tests for equality in a null-safe manner.

public abstract boolean

Returns:

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

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

public abstract boolean

Returns:

true if the CharSequences are equal (case-sensitive), or both null
equals
(String
the first CharSequence, may be null
str1
,
String
the second CharSequence, may be null
str2
)

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

public 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 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 abstract int

Returns:

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

Finds the first index within a CharSequence, handling null.

public boolean

Returns:

whether to ignore case.
isCaseSensitive
()

Tests whether to ignore case.

pack-priv boolean

Returns:

whether null is less when comparing.
isNullIsLess
()

Tests whether null is less when comparing.

public 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
str
,
final CharSequence
the CharSequence to find, may be null
searchStr
)

Finds the last index within a CharSequence, handling null.

public abstract int

Returns:

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

Finds the last index within a CharSequence, handling null.

public 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 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 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 CharSequence
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 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 CharSequence
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 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 (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 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
,
String
the String to search for (case-insensitive), may be null
searchString
,
final String
the String to replace it with, may be null
replacement
,
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 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 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 boolean

Returns:

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

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

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait