Class StringIterate
java.lang.Object
org.eclipse.collections.impl.utility.StringIterate
public final class StringIterate extends Object
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 of the 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 Type Method Description static booleanallSatisfy(String string, CharPredicate predicate)Deprecated.since 7.0.static booleanallSatisfy(String string, CodePointPredicate predicate)Deprecated.since 7.0.static booleanallSatisfyChar(String string, CharPredicate predicate)static booleanallSatisfyCodePoint(String string, CodePointPredicate predicate)static booleananySatisfy(String string, CharPredicate predicate)Deprecated.since 7.0.static booleananySatisfy(String string, CodePointPredicate predicate)Deprecated.since 7.0.static booleananySatisfyChar(String string, CharPredicate predicate)static booleananySatisfyCodePoint(String string, CodePointPredicate predicate)static CharAdapterasCharAdapter(String string)static CodePointAdapterasCodePointAdapter(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>chunk(String string, int size)Partitions String in fixed size chunks.static Stringcollect(String string, CharToCharFunction function)Deprecated.since 7.0.static Stringcollect(String string, CharFunction function)Deprecated.since 3.0.static Stringcollect(String string, CodePointFunction function)Deprecated.since 7.0.static StringcollectChar(String string, CharToCharFunction function)Transform the char elements to a new string using the specified functionfunction.static StringcollectCodePoint(String string, CodePointFunction function)Transform the int code point elements to a new string using the specified functionfunction.static intcount(String string, CharPredicate predicate)Deprecated.since 7.0.static intcount(String string, CodePointPredicate predicate)Deprecated.since 7.0.static intcount(String string, CharPredicate predicate)Deprecated.since 3.0.static intcountChar(String string, CharPredicate predicate)Count the number of elements that return true for the specifiedpredicate.static intcountCodePoint(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 Characterdetect(String string, CharPredicate predicate)Deprecated.since 7.0.static CharacterdetectChar(String string, CharPredicate predicate)Find the first element that returns true for the specifiedpredicate.static CharacterdetectCharIfNone(String string, CharPredicate predicate, char resultIfNone)Find the first element that returns true for the specifiedpredicate.static CharacterdetectCharIfNone(String string, CharPredicate predicate, String resultIfNone)Find the first element that returns true for the specifiedpredicate.static CharacterdetectIfNone(String string, CharPredicate predicate, char resultIfNone)Deprecated.since 7.0.static CharacterdetectIfNone(String string, CharPredicate predicate, String resultIfNone)Deprecated.since 7.0.static StringenglishToLowerCase(String string)static StringenglishToUpperCase(String string)static voidforEach(String string, CharProcedure procedure)Deprecated.since 7.0.static voidforEach(String string, CharProcedure procedure)Deprecated.since 3.0.static voidforEach(String string, CodePointProcedure procedure)Deprecated.since 7.0.static voidforEachChar(String string, CharProcedure procedure)For each char in thestring, execute theCharProcedure.static voidforEachCodePoint(String string, CodePointProcedure procedure)For each int code point in thestring, execute theCodePointProcedure.static voidforEachToken(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 voidforEachTrimmedToken(String string, String separator, Procedure<String> procedure)static StringgetFirstToken(String value, String separator)static StringgetLastToken(String value, String separator)static <T, R> RinjectIntoTokens(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 booleanisAlphaNumeric(String string)static booleanisEmpty(String string)static booleanisEmptyOrWhitespace(String string)static booleanisNumber(String string)static booleanisSurrogate(String string, int i)static booleannoneSatisfy(String string, CharPredicate predicate)Deprecated.since 7.0.static booleannoneSatisfy(String string, CodePointPredicate predicate)Deprecated.since 7.0.static booleannoneSatisfyChar(String string, CharPredicate predicate)static booleannoneSatisfyCodePoint(String string, CodePointPredicate predicate)static booleannotEmpty(String string)static booleannotEmptyOrWhitespace(String string)static intnumberOfChars(String string, int i)static intoccurrencesOf(String string, char value)Deprecated.since 7.0.static intoccurrencesOf(String string, int value)Deprecated.since 7.0.static intoccurrencesOf(String string, String singleCharacter)Count the number of occurrences of the specifiedstring.static intoccurrencesOfChar(String string, char value)Count the number of occurrences of the specified char.static intoccurrencesOfCodePoint(String string, int value)Count the number of occurrences of the specified int code point.static StringpadOrTrim(String message, int targetLength)static Stringreject(String string, CharPredicate predicate)Deprecated.since 7.0.static Stringreject(String string, CodePointPredicate predicate)Deprecated.since 7.0.static StringrejectChar(String string, CharPredicate predicate)static StringrejectCodePoint(String string, CodePointPredicate predicate)static Stringrepeat(char c, int repeatTimes)static Stringrepeat(String template, int repeatTimes)static voidreverseForEach(String string, CharProcedure procedure)Deprecated.since 7.0.static voidreverseForEach(String string, CodePointProcedure procedure)Deprecated.since 7.0.static voidreverseForEachChar(String string, CharProcedure procedure)For each char in thestringin reverse order, execute theCharProcedure.static voidreverseForEachCodePoint(String string, CodePointProcedure procedure)For each int code point in thestringin reverse order, execute theCodePointProcedure.static Stringselect(String string, CharPredicate predicate)Deprecated.since 7.0.static Stringselect(String string, CodePointPredicate predicate)Deprecated.since 7.0.static StringselectChar(String string, CharPredicate predicate)static StringselectCodePoint(String string, CodePointPredicate predicate)static Twin<String>splitAtIndex(String aString, int index)static MutableBag<Character>toBag(String string)static CodePointListtoCodePointList(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 aMutableMapusing 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 aMutableMapusing 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 aMutableMapusing 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>toList(String string)static MutableBag<Character>toLowercaseBag(String string)static MutableList<Character>toLowercaseList(String string)static MutableSet<Character>toLowercaseSet(String string)static MutableSet<Character>toSet(String string)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 aMutableMapusing 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 aMutableMapusing 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 aMutableMapusing 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 thestringin reverse order, execute theCharProcedure. -
reverseForEachChar
For each char in thestringin reverse order, execute theCharProcedure.- Since:
- 7.0
-
reverseForEach
Deprecated.since 7.0. UsereverseForEachCodePoint(String, CodePointProcedure)instead.For each int code point in thestringin reverse order, execute theCodePointProcedure. -
reverseForEachCodePoint
For each int code point in thestringin 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
public static Character detectCharIfNone(String string, CharPredicate predicate, char resultIfNone)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
stringanswer true for the specifiedpredicate.
-
anySatisfyChar
- Returns:
- true if any of the characters in the
stringanswer 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
stringanswer true for the specifiedpredicate.
-
anySatisfyCodePoint
- Returns:
- true if any of the code points in the
stringanswer true for the specifiedpredicate. - Since:
- 7.0
-
allSatisfy
Deprecated.since 7.0. UseallSatisfyChar(String, CharPredicate)instead.- Returns:
- true if all of the characters in the
stringanswer true for the specifiedpredicate.
-
allSatisfyChar
- Returns:
- true if all of the characters in the
stringanswer true for the specifiedpredicate. - Since:
- 7.0
-
allSatisfy
Deprecated.since 7.0. UseallSatisfyCodePoint(String, CodePointPredicate)instead.- Returns:
- true if all of the code points in the
stringanswer true for the specifiedpredicate.
-
allSatisfyCodePoint
- Returns:
- true if all of the code points in the
stringanswer 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
stringanswer true for the specifiedpredicate.
-
noneSatisfyChar
- Returns:
- true if none of the characters in the
stringanswer 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
stringanswer true for the specifiedpredicate.
-
noneSatisfyCodePoint
- Returns:
- true if none of the code points in the
stringanswer true for the specifiedpredicate. - Since:
- 7.0
-
select
Deprecated.since 7.0. UseselectChar(String, CharPredicate)instead.- Returns:
- a new string with all of the characters that return true for the specified
predicate.
-
selectChar
- Returns:
- a new string with all of 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 of the code points that return true for the specified
predicate.
-
selectCodePoint
- Returns:
- a new string with all of 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 of the characters that return true for the specified
predicate.
-
rejectChar
- Returns:
- a new string excluding all of 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 of the code points that return true for the specified
predicate.
-
rejectCodePoint
- Returns:
- a new string excluding all of 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
MutableListcontainingStrings 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
-