Class StringIterate
java.lang.Object
org.eclipse.collections.impl.utility.StringIterate
A string is essentially an array of characters. In Smalltalk a String is a subclass of ArrayedCollection, which means
it supports the Collection protocol. StringIterate implements the methods available on the collection protocol that
make sense for Strings. Some methods are over-specialized, in the form of englishToUppercase() which is a fast
form of uppercase, but does not work for different locales.
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
allSatisfy
(String string, CharPredicate predicate) Deprecated.since 7.0.static boolean
allSatisfy
(String string, CodePointPredicate predicate) Deprecated.since 7.0.static boolean
allSatisfyChar
(String string, CharPredicate predicate) static boolean
allSatisfyCodePoint
(String string, CodePointPredicate predicate) static boolean
anySatisfy
(String string, CharPredicate predicate) Deprecated.since 7.0.static boolean
anySatisfy
(String string, CodePointPredicate predicate) Deprecated.since 7.0.static boolean
anySatisfyChar
(String string, CharPredicate predicate) static boolean
anySatisfyCodePoint
(String string, CodePointPredicate predicate) static CharAdapter
asCharAdapter
(String string) static CodePointAdapter
asCodePointAdapter
(String string) static MutableSet<Character>
asLowercaseSet
(String string) Deprecated.in 3.0.static MutableSet<Character>
asUppercaseSet
(String string) Deprecated.in 3.0.static MutableList<String>
Partitions String in fixed size chunks.static String
collect
(String string, CharToCharFunction function) Deprecated.since 7.0.static String
collect
(String string, CharFunction function) Deprecated.since 3.0.static String
collect
(String string, CodePointFunction function) Deprecated.since 7.0.static String
collectChar
(String string, CharToCharFunction function) Transform the char elements to a new string using the specified functionfunction
.static String
collectCodePoint
(String string, CodePointFunction function) Transform the int code point elements to a new string using the specified functionfunction
.static int
count
(String string, CharPredicate predicate) Deprecated.since 7.0.static int
count
(String string, CodePointPredicate predicate) Deprecated.since 7.0.static int
count
(String string, CharPredicate predicate) Deprecated.since 3.0.static int
countChar
(String string, CharPredicate predicate) Count the number of elements that return true for the specifiedpredicate
.static int
countCodePoint
(String string, CodePointPredicate predicate) Count the number of elements that return true for the specifiedpredicate
.static MutableList<String>
csvTokensToList
(String string) Deprecated.in 3.0.static MutableList<String>
csvTokensToReverseSortedList
(String string) Deprecated.in 3.0.static MutableSet<String>
csvTokensToSet
(String string) Deprecated.in 3.0.static MutableList<String>
csvTokensToSortedList
(String string) Deprecated.in 3.0.static MutableList<String>
csvTrimmedTokensToList
(String string) Deprecated.in 3.0.static MutableList<String>
csvTrimmedTokensToSortedList
(String string) Deprecated.in 3.0.static Character
detect
(String string, CharPredicate predicate) Deprecated.since 7.0.static Character
detectChar
(String string, CharPredicate predicate) Find the first element that returns true for the specifiedpredicate
.static Character
detectCharIfNone
(String string, CharPredicate predicate, char resultIfNone) Find the first element that returns true for the specifiedpredicate
.static Character
detectCharIfNone
(String string, CharPredicate predicate, String resultIfNone) Find the first element that returns true for the specifiedpredicate
.static Character
detectIfNone
(String string, CharPredicate predicate, char resultIfNone) Deprecated.since 7.0.static Character
detectIfNone
(String string, CharPredicate predicate, String resultIfNone) Deprecated.since 7.0.static String
englishToLowerCase
(String string) static String
englishToUpperCase
(String string) static void
forEach
(String string, CharProcedure procedure) Deprecated.since 7.0.static void
forEach
(String string, CharProcedure procedure) Deprecated.since 3.0.static void
forEach
(String string, CodePointProcedure procedure) Deprecated.since 7.0.static void
forEachChar
(String string, CharProcedure procedure) For each char in thestring
, execute theCharProcedure
.static void
forEachCodePoint
(String string, CodePointProcedure procedure) For each int code point in thestring
, execute theCodePointProcedure
.static void
forEachToken
(String string, String separator, Procedure<String> procedure) For each token in a string separated by the specified separator, execute the specified StringProcedure by calling the valueOfString method.static void
forEachTrimmedToken
(String string, String separator, Procedure<String> procedure) static String
getFirstToken
(String value, String separator) static String
getLastToken
(String value, String separator) static <T,
R> R injectIntoTokens
(String string, String separator, R injectedValue, Function2<? super R, String, ? extends R> function) For each token in a string separated by the specified separator, execute the specified Function2, returning the result value from the function.static boolean
isAlphaNumeric
(String string) static boolean
static boolean
isEmptyOrWhitespace
(String string) static boolean
static boolean
isSurrogate
(String string, int i) static boolean
noneSatisfy
(String string, CharPredicate predicate) Deprecated.since 7.0.static boolean
noneSatisfy
(String string, CodePointPredicate predicate) Deprecated.since 7.0.static boolean
noneSatisfyChar
(String string, CharPredicate predicate) static boolean
noneSatisfyCodePoint
(String string, CodePointPredicate predicate) static boolean
static boolean
notEmptyOrWhitespace
(String string) static int
numberOfChars
(String string, int i) static int
occurrencesOf
(String string, char value) Deprecated.since 7.0.static int
occurrencesOf
(String string, int value) Deprecated.since 7.0.static int
occurrencesOf
(String string, String singleCharacter) Count the number of occurrences of the specifiedstring
.static int
occurrencesOfChar
(String string, char value) Count the number of occurrences of the specified char.static int
occurrencesOfCodePoint
(String string, int value) Count the number of occurrences of the specified int code point.static String
static String
reject
(String string, CharPredicate predicate) Deprecated.since 7.0.static String
reject
(String string, CodePointPredicate predicate) Deprecated.since 7.0.static String
rejectChar
(String string, CharPredicate predicate) static String
rejectCodePoint
(String string, CodePointPredicate predicate) static String
repeat
(char c, int repeatTimes) static String
static void
reverseForEach
(String string, CharProcedure procedure) Deprecated.since 7.0.static void
reverseForEach
(String string, CodePointProcedure procedure) Deprecated.since 7.0.static void
reverseForEachChar
(String string, CharProcedure procedure) For each char in thestring
in reverse order, execute theCharProcedure
.static void
reverseForEachCodePoint
(String string, CodePointProcedure procedure) For each int code point in thestring
in reverse order, execute theCodePointProcedure
.static String
select
(String string, CharPredicate predicate) Deprecated.since 7.0.static String
select
(String string, CodePointPredicate predicate) Deprecated.since 7.0.static String
selectChar
(String string, CharPredicate predicate) static String
selectCodePoint
(String string, CodePointPredicate predicate) splitAtIndex
(String aString, int index) static MutableBag<Character>
static CodePointList
toCodePointList
(String string) static MutableList<String>
tokensToList
(String string, String separator) Converts a string of tokens separated by the specified separator to aMutableList
.static MutableMap<String,
String> tokensToMap
(String string) Converts a string of tokens to aMutableMap
using a | to separate pairs, and a : to separate key and value.static MutableMap<String,
String> tokensToMap
(String string, String pairSeparator, String keyValueSeparator) Converts a string of tokens to aMutableMap
using the specified separators.static <K,
V> MutableMap<K, V> tokensToMap
(String string, String separator, String keyValueSeparator, Function<String, K> keyFunction, Function<String, V> valueFunction) Converts a string of tokens to aMutableMap
using the specified 'key' and 'value' Functions.static MutableList<String>
tokensToReverseSortedList
(String string, String separator) Converts a string of tokens separated by the specified separator to a reverse sortedMutableList
.static MutableSet<String>
tokensToSet
(String string, String separator) Converts a string of tokens to aMutableSet
.static MutableList<String>
tokensToSortedList
(String string, String separator) Converts a string of tokens separated by the specified separator to a sortedMutableList
.static MutableList<Character>
static MutableBag<Character>
toLowercaseBag
(String string) static MutableList<Character>
toLowercaseList
(String string) static MutableSet<Character>
toLowercaseSet
(String string) static MutableSet<Character>
static MutableBag<Character>
toUppercaseBag
(String string) static MutableList<Character>
toUppercaseList
(String string) static MutableSet<Character>
toUppercaseSet
(String string) static MutableList<String>
trimmedTokensToList
(String string, String separator) Converts a string of tokens separated by the specified separator to aMutableList
.static MutableList<String>
trimmedTokensToSortedList
(String string, String separator) Converts a string of tokens separated by the specified separator to a sortedMutableList
.
-
Method Details
-
asCharAdapter
- Since:
- 7.0.
-
asCodePointAdapter
- Since:
- 7.0.
-
toCodePointList
- Since:
- 7.0.
-
csvTokensToSortedList
Deprecated.in 3.0. Inlineable. Poorly named method. Does not actually deal properly with CSV. This is better handled in a separate library.Converts a string of tokens separated by the specified separator to a sortedMutableList
. -
csvTrimmedTokensToSortedList
Deprecated.in 3.0. Inlineable. Poorly named method. Does not actually deal properly with CSV. This is better handled in a separate library.Converts a string of tokens separated by the specified separator to a sortedMutableList
. -
tokensToSortedList
Converts a string of tokens separated by the specified separator to a sortedMutableList
. -
trimmedTokensToSortedList
Converts a string of tokens separated by the specified separator to a sortedMutableList
. -
csvTokensToList
Deprecated.in 3.0. Inlineable. Poorly named method. Does not actually deal properly with CSV. This is better handled in a separate library.Converts a string of tokens separated by commas to aMutableList
. -
csvTrimmedTokensToList
Deprecated.in 3.0. Inlineable. Poorly named method. Does not actually deal properly with CSV. This is better handled in a separate library.Converts a string of tokens separated by commas to aMutableList
. -
tokensToList
Converts a string of tokens separated by the specified separator to aMutableList
. -
trimmedTokensToList
Converts a string of tokens separated by the specified separator to aMutableList
. -
csvTokensToSet
Deprecated.in 3.0. Inlineable. Poorly named method. Does not actually deal properly with CSV. This is better handled in a separate library.Converts a string of tokens separated by commas to aMutableSet
. -
tokensToSet
Converts a string of tokens to aMutableSet
. -
tokensToMap
Converts a string of tokens to aMutableMap
using a | to separate pairs, and a : to separate key and value. e.g. "1:Sunday|2:Monday|3:Tuesday|4:Wednesday|5:Thursday|6:Friday|7:Saturday" -
tokensToMap
public static MutableMap<String,String> tokensToMap(String string, String pairSeparator, String keyValueSeparator) Converts a string of tokens to aMutableMap
using the specified separators. -
tokensToMap
public static <K,V> MutableMap<K,V> tokensToMap(String string, String separator, String keyValueSeparator, Function<String, K> keyFunction, Function<String, V> valueFunction) Converts a string of tokens to aMutableMap
using the specified 'key' and 'value' Functions. e.g. "1:2,2:1,3:3" with both functions as Functions.getStringToInteger(), will be translated a map {[1,2],[2,1],[3,3]} -
csvTokensToReverseSortedList
Deprecated.in 3.0. Inlineable. Poorly named method. Does not actually deal properly with CSV. This is better handled in a separate library.Converts a string of tokens separated by the specified separator to a reverse sortedMutableList
. -
tokensToReverseSortedList
Converts a string of tokens separated by the specified separator to a reverse sortedMutableList
. -
forEachToken
For each token in a string separated by the specified separator, execute the specified StringProcedure by calling the valueOfString method. -
injectIntoTokens
public static <T,R> R injectIntoTokens(String string, String separator, R injectedValue, Function2<? super R, String, ? extends R> function) For each token in a string separated by the specified separator, execute the specified Function2, returning the result value from the function. For more information, seeIterate.injectInto(Object, Iterable, Function2)
-
forEachTrimmedToken
-
forEach
Deprecated.since 3.0. UseforEach(String, CharProcedure)
instead.For each character in thestring
, execute theCharProcedure
. -
forEach
Deprecated.since 7.0. UseforEachChar(String, CharProcedure)
instead.For each character in thestring
, execute theCharProcedure
. -
forEachChar
For each char in thestring
, execute theCharProcedure
.- Since:
- 7.0
-
forEach
Deprecated.since 7.0. UseforEachCodePoint(String, CodePointProcedure)
instead.For each int code point in thestring
, execute theCodePointProcedure
. -
forEachCodePoint
For each int code point in thestring
, execute theCodePointProcedure
.- Since:
- 7.0
-
reverseForEach
Deprecated.since 7.0. UsereverseForEachChar(String, CharProcedure)
instead.For each char in thestring
in reverse order, execute theCharProcedure
. -
reverseForEachChar
For each char in thestring
in reverse order, execute theCharProcedure
.- Since:
- 7.0
-
reverseForEach
Deprecated.since 7.0. UsereverseForEachCodePoint(String, CodePointProcedure)
instead.For each int code point in thestring
in reverse order, execute theCodePointProcedure
. -
reverseForEachCodePoint
For each int code point in thestring
in reverse order, execute theCodePointProcedure
.- Since:
- 7.0
-
numberOfChars
-
isSurrogate
-
count
Deprecated.since 3.0.Count the number of elements that return true for the specifiedpredicate
. -
count
Deprecated.since 7.0. UsecountChar(String, CharPredicate)
instead.Count the number of elements that return true for the specifiedpredicate
. -
countChar
Count the number of elements that return true for the specifiedpredicate
.- Since:
- 7.0
-
count
Deprecated.since 7.0. UsecountCodePoint(String, CodePointPredicate)
instead.Count the number of elements that return true for the specifiedpredicate
. -
countCodePoint
Count the number of elements that return true for the specifiedpredicate
.- Since:
- 7.0
-
collect
Deprecated.since 3.0. Usecollect(String, CharToCharFunction)
instead. -
collect
Deprecated.since 7.0. UsecollectChar(String, CharToCharFunction)
instead.Transform the char elements to a new string using the specified functionfunction
. -
collectChar
Transform the char elements to a new string using the specified functionfunction
.- Since:
- 7.0
-
collect
Deprecated.since 7.0. UsecollectCodePoint(String, CodePointFunction)
instead.Transform the int code point elements to a new string using the specified functionfunction
. -
collectCodePoint
Transform the int code point elements to a new string using the specified functionfunction
.- Since:
- 7.0
-
englishToUpperCase
-
englishToLowerCase
-
detect
Deprecated.since 7.0. UsedetectChar(String, CharPredicate)
instead.Find the first element that returns true for the specifiedpredicate
. -
detectChar
Find the first element that returns true for the specifiedpredicate
.- Since:
- 7.0
-
detectIfNone
@Deprecated public static Character detectIfNone(String string, CharPredicate predicate, char resultIfNone) Deprecated.since 7.0. UsedetectCharIfNone(String, CharPredicate, char)
instead.Find the first element that returns true for the specifiedpredicate
. Return the default char if no value is found. -
detectCharIfNone
Find the first element that returns true for the specifiedpredicate
. Return the default char if no value is found. -
detectIfNone
@Deprecated public static Character detectIfNone(String string, CharPredicate predicate, String resultIfNone) Deprecated.since 7.0. UsedetectCharIfNone(String, CharPredicate, String)
instead.Find the first element that returns true for the specifiedpredicate
. Return the first char of the default string if no value is found. -
detectCharIfNone
public static Character detectCharIfNone(String string, CharPredicate predicate, String resultIfNone) Find the first element that returns true for the specifiedpredicate
. Return the first char of the default string if no value is found. -
occurrencesOf
Deprecated.since 7.0. UseoccurrencesOfChar(String, char)
instead.Count the number of occurrences of the specified char. -
occurrencesOfChar
Count the number of occurrences of the specified char.- Since:
- 7.0
-
occurrencesOf
Deprecated.since 7.0. UseoccurrencesOfCodePoint(String, int)
instead.Count the number of occurrences of the specified int code point. -
occurrencesOfCodePoint
Count the number of occurrences of the specified int code point.- Since:
- 7.0
-
occurrencesOf
Count the number of occurrences of the specifiedstring
. -
anySatisfy
Deprecated.since 7.0. UseanySatisfyChar(String, CharPredicate)
instead.- Returns:
- true if any of the characters in the
string
answer true for the specifiedpredicate
.
-
anySatisfyChar
- Returns:
- true if any of the characters in the
string
answer true for the specifiedpredicate
. - Since:
- 7.0
-
anySatisfy
Deprecated.since 7.0. UseanySatisfyCodePoint(String, CodePointPredicate)
instead.- Returns:
- true if any of the code points in the
string
answer true for the specifiedpredicate
.
-
anySatisfyCodePoint
- Returns:
- true if any of the code points in the
string
answer true for the specifiedpredicate
. - Since:
- 7.0
-
allSatisfy
Deprecated.since 7.0. UseallSatisfyChar(String, CharPredicate)
instead.- Returns:
- true if all the characters in the
string
answer true for the specifiedpredicate
.
-
allSatisfyChar
- Returns:
- true if all the characters in the
string
answer true for the specifiedpredicate
. - Since:
- 7.0
-
allSatisfy
Deprecated.since 7.0. UseallSatisfyCodePoint(String, CodePointPredicate)
instead.- Returns:
- true if all the code points in the
string
answer true for the specifiedpredicate
.
-
allSatisfyCodePoint
- Returns:
- true if all the code points in the
string
answer true for the specifiedpredicate
. - Since:
- 7.0
-
noneSatisfy
Deprecated.since 7.0. UsenoneSatisfyChar(String, CharPredicate)
instead.- Returns:
- true if none of the characters in the
string
answer true for the specifiedpredicate
.
-
noneSatisfyChar
- Returns:
- true if none of the characters in the
string
answer true for the specifiedpredicate
. - Since:
- 7.0
-
noneSatisfy
Deprecated.since 7.0. UsenoneSatisfyCodePoint(String, CodePointPredicate)
instead.- Returns:
- true if none of the code points in the
string
answer true for the specifiedpredicate
.
-
noneSatisfyCodePoint
- Returns:
- true if none of the code points in the
string
answer true for the specifiedpredicate
. - Since:
- 7.0
-
select
Deprecated.since 7.0. UseselectChar(String, CharPredicate)
instead.- Returns:
- a new string with all the characters that return true for the specified
predicate
.
-
selectChar
- Returns:
- a new string with all the characters that return true for the specified
predicate
. - Since:
- 7.0
-
select
Deprecated.since 7.0. UseselectCodePoint(String, CodePointPredicate)
instead.- Returns:
- a new string with all the code points that return true for the specified
predicate
.
-
selectCodePoint
- Returns:
- a new string with all the code points that return true for the specified
predicate
. - Since:
- 7.0
-
reject
Deprecated.since 7.0. UserejectChar(String, CharPredicate)
instead.- Returns:
- a new string excluding all the characters that return true for the specified
predicate
.
-
rejectChar
- Returns:
- a new string excluding all the characters that return true for the specified
predicate
. - Since:
- 7.0
-
reject
Deprecated.since 7.0. UserejectCodePoint(String, CodePointPredicate)
instead.- Returns:
- a new string excluding all the code points that return true for the specified
predicate
.
-
rejectCodePoint
- Returns:
- a new string excluding all the code points that return true for the specified
predicate
. - Since:
- 7.0
-
getLastToken
-
getFirstToken
-
isEmpty
-
isEmptyOrWhitespace
-
isNumber
-
isAlphaNumeric
-
notEmpty
-
notEmptyOrWhitespace
-
repeat
-
repeat
-
padOrTrim
-
toList
-
toLowercaseList
-
toUppercaseList
-
toBag
-
toLowercaseBag
-
toUppercaseBag
-
toSet
-
chunk
Partitions String in fixed size chunks.- Parameters:
size
- the number of characters per chunk- Returns:
- A
MutableList
containingString
s of sizesize
, except the last will be truncated (i.e. shorter) if the characters don't divide evenly. - Since:
- 5.2
-
asUppercaseSet
Deprecated.in 3.0. Inlineable. -
toUppercaseSet
-
asLowercaseSet
Deprecated.in 3.0. Inlineable. -
toLowercaseSet
-
splitAtIndex
-