public final class StringUtil extends Object
Modifier and Type | Class and Description |
---|---|
static interface |
StringUtil.Constants |
Modifier and Type | Method and Description |
---|---|
static <T extends Enum<T>> |
caseInsensitiveValueOf(Class<T> enumType,
String name) |
static boolean |
endsWithIgnoreCase(String text,
String suffix)
Tests if the string ends with the specified suffix.
|
static boolean |
equalsIgnoreCase(String s1,
String s2) |
static String |
getFirstToken(String str,
String delimiter)
Return the first token in the string.
|
static String |
getLastToken(String str,
String delimiter)
Return the last token in the string.
|
static String |
getStackTrace(Throwable t) |
static List<String> |
getTokens(String str,
String delimiter)
Return the tokens in a string in a list.
|
static int |
indexOfIgnoreCase(String text,
String str)
Returns the index within this string of the first occurrence of the
specified substring.
|
static boolean |
isDigit(char c) |
static boolean |
isEmpty(String text)
Returns whether the specified text is either empty or null.
|
static boolean |
isLetter(char c) |
static boolean |
isLetterOrDigit(char c) |
static String |
join(Collection<String> strings,
String delimiter)
Join string pieces and separate with a delimiter.
|
static String |
replace(String source,
String search,
String replace)
Replace a single occurrence of the search string with the replace string
in the source string.
|
static String |
replaceAll(String source,
String search,
String replace)
Replace all occurrences of the search string with the replace string
in the source string.
|
static List<String> |
split(String str,
String splitter)
Split a string into pieces based on delimiters.
|
static boolean |
startsWithIgnoreCase(String text,
String prefix)
Tests if the string starts with the specified prefix.
|
static List<String> |
tokenize(String str,
char delim) |
static String |
toString(Object[] array)
Return a stringified version of the array, using a ',' as a delimiter
|
static String |
toString(Object[] array,
String delim)
Return a stringified version of the array.
|
static String |
toString(Object[] array,
String delim,
boolean includeBrackets)
Return a stringified version of the array.
|
static String |
unescape(CharSequence string,
int quoteChar,
boolean useAsciiEscapes,
StringBuilder sb)
Unescape the given string
|
static <T> T |
valueOf(String value,
Class type)
Convert the given value to specified type.
|
public static String join(Collection<String> strings, String delimiter)
strings
- String pieces to joindelimiter
- Delimiter to put between string piecessplit(java.lang.String, java.lang.String)
public static String toString(Object[] array, String delim)
array
- the arraydelim
- the delimiter to use between array componentspublic static String toString(Object[] array, String delim, boolean includeBrackets)
array
- the arraydelim
- the delimiter to use between array componentspublic static String toString(Object[] array)
array
- the arraytoString(Object[], String)
public static List<String> split(String str, String splitter)
str
- Full stringsplitter
- Characters to split onjoin(java.util.Collection<java.lang.String>, java.lang.String)
public static String replace(String source, String search, String replace)
source
- the source string whose contents will be alteredsearch
- the string to search for in sourcereplace
- the string to substitute for search if presentpublic static String replaceAll(String source, String search, String replace)
source
- the source string whose contents will be alteredsearch
- the string to search for in sourcereplace
- the string to substitute for search if presentpublic static List<String> getTokens(String str, String delimiter)
str
- String to be tokenizeddelimiter
- Characters which are delimit tokenspublic static String getLastToken(String str, String delimiter)
str
- String to be tokenizeddelimiter
- Characters which are delimit tokenspublic static String getFirstToken(String str, String delimiter)
str
- String to be tokenizeddelimiter
- Characters which are delimit tokenspublic static boolean isEmpty(String text)
Returns whether the specified text is either empty or null.
text
- The text to check; may be null;public static int indexOfIgnoreCase(String text, String str)
isthis.startsWith(str, k)
true
.text
- any string.str
- any string.-1
is returned. If the text or
str argument is null or empty then -1
is returned.public static boolean startsWithIgnoreCase(String text, String prefix)
text
- the string to test.prefix
- the prefix.true
if the character sequence represented by the
argument is a prefix of the character sequence represented by
this string; false
otherwise.
Note also that true
will be returned if the
prefix is an empty string or is equal to the text
String
object as determined by the
Object.equals(Object)
method. If the text or
prefix argument is null false
is returned.public static boolean endsWithIgnoreCase(String text, String suffix)
public static boolean isLetter(char c)
public static boolean isDigit(char c)
public static boolean isLetterOrDigit(char c)
public static <T> T valueOf(String value, Class type)
value
- type
- public static <T extends Enum<T>> T caseInsensitiveValueOf(Class<T> enumType, String name)
public static String unescape(CharSequence string, int quoteChar, boolean useAsciiEscapes, StringBuilder sb)
string
- quoteChar
- useAsciiEscapes
- sb
- a scratch buffer to useCopyright © 2019. All rights reserved.