public final class StringUtil extends Object
java.lang.String
-related utility methods.Modifier and Type | Class and Description |
---|---|
static class |
StringUtil.AbstractIndexOf |
static interface |
StringUtil.IndexOf |
Modifier and Type | Field and Description |
---|---|
static Predicate<CharSequence> |
IS_BLANK
A predicate that evaluates its subject with
isBlank(CharSequence) . |
Modifier and Type | Method and Description |
---|---|
static Iterable<Character> |
asIterable(CharSequence subject)
Wraps a char sequence as an iterable.
|
static StringUtil.IndexOf |
boyerMooreHorspoolIndexOf(char[][] needle)
Implementation of the Boyer-Moore-Horspool string search algorithm.
|
static StringUtil.IndexOf |
boyerMooreHorspoolIndexOf(CharSequence needle)
Implementation of the Boyer-Moore-Horspool string search algorithm.
|
static int |
compareTo(CharSequence cs1,
CharSequence cs2)
Naturally,
CharSequence does not extend Comparable . |
static boolean |
containsAny(String subject,
String characters) |
static boolean |
equals(CharSequence cs1,
CharSequence cs2)
Naturally,
CharSequence does not refine Object.equals(Object) . |
static boolean |
equalsIgnoreCase(String s1,
String s2) |
static String |
firstLetterToLowerCase(String s) |
static String |
firstLetterToUpperCase(String s) |
static StringUtil.IndexOf |
indexOf(char[] needle)
Runtime-optimized reimplementation of
String.indexOf(String) and String.lastIndexOf(String) . |
static StringUtil.IndexOf |
indexOf(char[][] needle)
Creates a highly optimized
StringUtil.IndexOf object that searches for "multivalent" needle. |
static StringUtil.IndexOf |
indexOf(CharSequence needle)
Runtime-optimized reimplementation of
String.indexOf(String) and String.lastIndexOf(String) . |
static boolean |
isBlank(CharSequence cs) |
static Iterator<Character> |
iterator(CharSequence subject)
Returns an iterator that produces the characters of the subject, from index 0 through index
subject.length() - 1 . |
static String |
join(Collection<? extends Object> elements,
String glue)
Converts all elements to string and concatenates these, separated by the glue.
|
static String |
lessTrailingLineSeparators(String s) |
static StringUtil.IndexOf |
naiveIndexOf(CharSequence needle) |
static String |
repeat(int n,
char c) |
static String |
repeat(int n,
char[] chars) |
static String |
repeat(int n,
CharSequence cs) |
static Iterator<Character> |
reverseIterator(CharSequence subject)
Returns an iterator that produces the characters of the subject in reverse order, from index
subject.length() - 1 through index 0. |
public static final Predicate<CharSequence> IS_BLANK
isBlank(CharSequence)
.public static String join(Collection<? extends Object> elements, String glue)
public static boolean equals(CharSequence cs1, CharSequence cs2)
CharSequence
does not refine Object.equals(Object)
. This method fills the gap.public static int compareTo(CharSequence cs1, CharSequence cs2)
CharSequence
does not extend Comparable
. This method fills the gap.public static String repeat(int n, char c)
public static String repeat(int n, char[] chars)
public static String repeat(int n, CharSequence cs)
public static boolean isBlank(CharSequence cs)
public static String firstLetterToUpperCase(String s)
public static String firstLetterToLowerCase(String s)
public static Iterable<Character> asIterable(CharSequence subject)
public static Iterator<Character> iterator(CharSequence subject)
subject.length() - 1
.public static Iterator<Character> reverseIterator(CharSequence subject)
subject.length() - 1
through index 0.public static String lessTrailingLineSeparators(String s)
'\r'
and '\n'
chopped offBufferedReader.readLine()
public static boolean containsAny(String subject, String characters)
public static boolean equalsIgnoreCase(@Nullable String s1, @Nullable String s2)
ObjectUtil.equals(Object, Object)
public static StringUtil.IndexOf indexOf(char[] needle)
String.indexOf(String)
and String.lastIndexOf(String)
.
This method returns an implementation that performs at least as well as the String
methods by
analyzing the needle (the string to search for).
needle
- The string to search forpublic static StringUtil.IndexOf indexOf(CharSequence needle)
String.indexOf(String)
and String.lastIndexOf(String)
.
This method returns an implementation that performs at least as well as the String
methods by
analyzing the needle (the string to search for).
needle
- The string to search forpublic static StringUtil.IndexOf naiveIndexOf(CharSequence needle)
String.indexOf(String)
and String.lastIndexOf(String)
, which implements
a naive string search algorithmpublic static StringUtil.IndexOf boyerMooreHorspoolIndexOf(CharSequence needle)
needle
- The string to search forpublic static StringUtil.IndexOf indexOf(char[][] needle)
StringUtil.IndexOf
object that searches for "multivalent" needle.
Multivalent means that a character in the haystack equals any of needle[offset]
.
E.g. a case-insensitive search for "abc"
in the haystack
string could be implemented like
this:
int idx = StringUtil.indexOf(new char[][] { { 'a', 'A' }, { 'b', 'B' }, { 'c', 'C' } }).indexOf(haystack);
public static StringUtil.IndexOf boyerMooreHorspoolIndexOf(char[][] needle)
Notice that the indexOf(char[][])
method performs some extra optimizations, e.g. when the needle
is actually univalent (all of needle[n].length
are 1), or when the needle is very short.
Copyright © 2018 Arno Unkrig. All rights reserved.