Class Strings.CiStrings
- Enclosing class:
Strings
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.commons.lang3.Strings
Strings.Builder -
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintCompare two Strings lexicographically, likeString.compareTo(String).booleancontains(CharSequence str, CharSequence searchStr) Tests if CharSequence contains a search CharSequence, handlingnull.booleanequals(CharSequence cs1, CharSequence cs2) Compares two CharSequences, returningtrueif they represent equal sequences of characters.booleanCompares two CharSequences, returningtrueif they represent equal sequences of characters.intindexOf(CharSequence str, CharSequence searchStr, int startPos) Finds the first index within a CharSequence, handlingnull.intlastIndexOf(CharSequence str, CharSequence searchStr, int startPos) Finds the last index within a CharSequence, handlingnull.Methods inherited from class org.apache.commons.lang3.Strings
appendIfMissing, builder, containsAny, endsWith, endsWithAny, equalsAny, indexOf, isCaseSensitive, isNullIsLess, lastIndexOf, prependIfMissing, remove, removeEnd, removeStart, replace, replace, replaceOnce, startsWith, startsWithAny
-
Constructor Details
-
CiStrings
private CiStrings(boolean nullIsLess)
-
-
Method Details
-
compare
Description copied from class:StringsCompare two Strings lexicographically, likeString.compareTo(String).The return values are:
int = 0, ifstr1is equal tostr2(or bothnull)int < 0, ifstr1is less thanstr2int > 0, ifstr1is greater thanstr2
This is a
nullsafe version of :str1.compareTo(str2)
nullvalue is considered less than non-nullvalue. Twonullreferences are considered equal.Case-sensitive examples
Strings.CS.compare(null, null) = 0 Strings.CS.compare(null , "a") < 0 Strings.CS.compare("a", null) > 0 Strings.CS.compare("abc", "abc") = 0 Strings.CS.compare("a", "b") < 0 Strings.CS.compare("b", "a") > 0 Strings.CS.compare("a", "B") > 0 Strings.CS.compare("ab", "abc") < 0Case-insensitive examples
Strings.CI.compareIgnoreCase(null, null) = 0 Strings.CI.compareIgnoreCase(null , "a") < 0 Strings.CI.compareIgnoreCase("a", null) > 0 Strings.CI.compareIgnoreCase("abc", "abc") = 0 Strings.CI.compareIgnoreCase("abc", "ABC") = 0 Strings.CI.compareIgnoreCase("a", "b") < 0 Strings.CI.compareIgnoreCase("b", "a") > 0 Strings.CI.compareIgnoreCase("a", "B") < 0 Strings.CI.compareIgnoreCase("A", "b") < 0 Strings.CI.compareIgnoreCase("ab", "ABC") < 0 -
contains
Description copied from class:StringsTests if CharSequence contains a search CharSequence, handlingnull. This method usesString.indexOf(String)if possible.A
nullCharSequence will returnfalse.Case-sensitive examples
Strings.CS.contains(null, *) = false Strings.CS.contains(*, null) = false Strings.CS.contains("", "") = true Strings.CS.contains("abc", "") = true Strings.CS.contains("abc", "a") = true Strings.CS.contains("abc", "z") = falseCase-insensitive examples
Strings.CI.containsIgnoreCase(null, *) = false Strings.CI.containsIgnoreCase(*, null) = false Strings.CI.containsIgnoreCase("", "") = true Strings.CI.containsIgnoreCase("abc", "") = true Strings.CI.containsIgnoreCase("abc", "a") = true Strings.CI.containsIgnoreCase("abc", "z") = false Strings.CI.containsIgnoreCase("abc", "A") = true Strings.CI.containsIgnoreCase("abc", "Z") = false -
equals
Description copied from class:StringsCompares two CharSequences, returningtrueif they represent equal sequences of characters.nulls are handled without exceptions. Twonullreferences are considered to be equal.Case-sensitive examples
Strings.CS.equals(null, null) = true Strings.CS.equals(null, "abc") = false Strings.CS.equals("abc", null) = false Strings.CS.equals("abc", "abc") = true Strings.CS.equals("abc", "ABC") = falseCase-insensitive examples
Strings.CI.equalsIgnoreCase(null, null) = true Strings.CI.equalsIgnoreCase(null, "abc") = false Strings.CI.equalsIgnoreCase("abc", null) = false Strings.CI.equalsIgnoreCase("abc", "abc") = true Strings.CI.equalsIgnoreCase("abc", "ABC") = true -
equals
Description copied from class:StringsCompares two CharSequences, returningtrueif they represent equal sequences of characters.nulls are handled without exceptions. Twonullreferences are considered to be equal.Case-sensitive examples
Strings.CS.equals(null, null) = true Strings.CS.equals(null, "abc") = false Strings.CS.equals("abc", null) = false Strings.CS.equals("abc", "abc") = true Strings.CS.equals("abc", "ABC") = falseCase-insensitive examples
Strings.CI.equalsIgnoreCase(null, null) = true Strings.CI.equalsIgnoreCase(null, "abc") = false Strings.CI.equalsIgnoreCase("abc", null) = false Strings.CI.equalsIgnoreCase("abc", "abc") = true Strings.CI.equalsIgnoreCase("abc", "ABC") = true -
indexOf
Description copied from class:StringsFinds the first index within a CharSequence, handlingnull. This method usesString.indexOf(String, int)if possible.A
nullCharSequence will return-1. A negative start position is treated as zero. An empty ("") search CharSequence always matches. A start position greater than the string length only matches an empty search CharSequence.Case-sensitive examples
Strings.CS.indexOf(null, *, *) = -1 Strings.CS.indexOf(*, null, *) = -1 Strings.CS.indexOf("", "", 0) = 0 Strings.CS.indexOf("", *, 0) = -1 (except when * = "") Strings.CS.indexOf("aabaabaa", "a", 0) = 0 Strings.CS.indexOf("aabaabaa", "b", 0) = 2 Strings.CS.indexOf("aabaabaa", "ab", 0) = 1 Strings.CS.indexOf("aabaabaa", "b", 3) = 5 Strings.CS.indexOf("aabaabaa", "b", 9) = -1 Strings.CS.indexOf("aabaabaa", "b", -1) = 2 Strings.CS.indexOf("aabaabaa", "", 2) = 2 Strings.CS.indexOf("abc", "", 9) = 3Case-insensitive examples
Strings.CI.indexOfIgnoreCase(null, *, *) = -1 Strings.CI.indexOfIgnoreCase(*, null, *) = -1 Strings.CI.indexOfIgnoreCase("", "", 0) = 0 Strings.CI.indexOfIgnoreCase("aabaabaa", "A", 0) = 0 Strings.CI.indexOfIgnoreCase("aabaabaa", "B", 0) = 2 Strings.CI.indexOfIgnoreCase("aabaabaa", "AB", 0) = 1 Strings.CI.indexOfIgnoreCase("aabaabaa", "B", 3) = 5 Strings.CI.indexOfIgnoreCase("aabaabaa", "B", 9) = -1 Strings.CI.indexOfIgnoreCase("aabaabaa", "B", -1) = 2 Strings.CI.indexOfIgnoreCase("aabaabaa", "", 2) = 2 Strings.CI.indexOfIgnoreCase("abc", "", 9) = -1- Specified by:
indexOfin classStrings- Parameters:
str- the CharSequence to check, may be nullsearchStr- the CharSequence to find, may be nullstartPos- the start position, negative treated as zero- Returns:
- the first index of the search CharSequence (always ≥ startPos), -1 if no match or
nullstring input
-
lastIndexOf
Description copied from class:StringsFinds the last index within a CharSequence, handlingnull. This method usesString.lastIndexOf(String, int)if possible.A
nullCharSequence will return-1. A negative start position returns-1. An empty ("") search CharSequence always matches unless the start position is negative. A start position greater than the string length searches the whole string. The search starts at the startPos and works backwards; matches starting after the start position are ignored.Case-sensitive examples
Strings.CS.lastIndexOf(null, *, *) = -1 Strings.CS.lastIndexOf(*, null, *) = -1 Strings.CS.lastIndexOf("aabaabaa", "a", 8) = 7 Strings.CS.lastIndexOf("aabaabaa", "b", 8) = 5 Strings.CS.lastIndexOf("aabaabaa", "ab", 8) = 4 Strings.CS.lastIndexOf("aabaabaa", "b", 9) = 5 Strings.CS.lastIndexOf("aabaabaa", "b", -1) = -1 Strings.CS.lastIndexOf("aabaabaa", "a", 0) = 0 Strings.CS.lastIndexOf("aabaabaa", "b", 0) = -1 Strings.CS.lastIndexOf("aabaabaa", "b", 1) = -1 Strings.CS.lastIndexOf("aabaabaa", "b", 2) = 2 Strings.CS.lastIndexOf("aabaabaa", "ba", 2) = 2Case-insensitive examples
Strings.CI.lastIndexOfIgnoreCase(null, *, *) = -1 Strings.CI.lastIndexOfIgnoreCase(*, null, *) = -1 Strings.CI.lastIndexOfIgnoreCase("aabaabaa", "A", 8) = 7 Strings.CI.lastIndexOfIgnoreCase("aabaabaa", "B", 8) = 5 Strings.CI.lastIndexOfIgnoreCase("aabaabaa", "AB", 8) = 4 Strings.CI.lastIndexOfIgnoreCase("aabaabaa", "B", 9) = 5 Strings.CI.lastIndexOfIgnoreCase("aabaabaa", "B", -1) = -1 Strings.CI.lastIndexOfIgnoreCase("aabaabaa", "A", 0) = 0 Strings.CI.lastIndexOfIgnoreCase("aabaabaa", "B", 0) = -1- Specified by:
lastIndexOfin classStrings- Parameters:
str- the CharSequence to check, may be nullsearchStr- the CharSequence to find, may be nullstartPos- the start position, negative treated as zero- Returns:
- the last index of the search CharSequence (always ≤ startPos), -1 if no match or
nullstring input
-