public final class StringUtils extends Object
| Modifier and Type | Field and Description |
|---|---|
static String |
AND |
static char |
AND_CHAR |
static String |
EMPTY_STRING |
static String[] |
EMPTY_STRING_ARRAY |
static String |
EQUAL |
static char |
EQUAL_CHAR |
static String |
HYPHEN |
static char |
HYPHEN_CHAR |
static int |
INDEX_NOT_FOUND |
static String |
QUESTION_MASK |
static char |
QUESTION_MASK_CHAR |
static String |
SEMICOLON |
static char |
SEMICOLON_CHAR |
static String |
SLASH |
static char |
SLASH_CHAR |
| Modifier and Type | Method and Description |
|---|---|
static String |
arrayToDelimitedString(Object[] arr,
String delim) |
static String |
camelToSplitName(String camelName,
String split) |
static byte |
decodeHexByte(CharSequence s,
int pos)
Decode a 2-digit hex byte from within a string.
|
static int |
decodeHexNibble(char c) |
static String |
deleteAny(String inString,
String charsToDelete) |
static String[] |
delimitedListToStringArray(String str,
String delimiter) |
static String[] |
delimitedListToStringArray(String str,
String delimiter,
String charsToDelete) |
static String |
getQueryStringValue(String qs,
String key) |
static String |
getServiceKey(Map<String,String> ps) |
static boolean |
isAllUpperCase(String str) |
static boolean |
isAnyEmpty(String... ss)
Checks if the strings contain at least on empty or null element.
|
static boolean |
isBlank(CharSequence cs) |
static boolean |
isContains(String[] values,
String value) |
static boolean |
isContains(String str,
char ch) |
static boolean |
isContains(String values,
String value) |
static boolean |
isEmpty(String str)
is empty string.
|
static boolean |
isEquals(String s1,
String s2) |
static boolean |
isInteger(String str)
is integer string.
|
static boolean |
isJavaIdentifier(String s)
Returns true if s is a legal Java identifier.
|
static boolean |
isNoneEmpty(String... ss)
Checks if the strings contain empty or null elements.
|
static boolean |
isNotContains(String str,
char ch) |
static boolean |
isNotEmpty(String str)
is not empty string.
|
static boolean |
isNumeric(String str,
boolean allowDot) |
static String |
join(Collection<String> coll,
String split) |
static String |
join(String[] array)
join string.
|
static String |
join(String[] array,
char split)
join string like javascript.
|
static String |
join(String[] array,
String split)
join string like javascript.
|
static int |
length(CharSequence cs)
Gets a CharSequence length or
0 if the CharSequence is
null. |
static String |
nullSafeToString(Object obj) |
static int |
parseInteger(String str) |
static Map<String,String> |
parseParameters(String rawParameters) |
static Map<String,String> |
parseQueryString(String qs)
parse query string to Parameters.
|
static String |
removeEnd(String str,
String remove)
Removes a substring only if it is at the end of a source string,
otherwise returns the source string.
|
static String |
repeat(char ch,
int repeat)
Returns padding using the specified delimiter repeated
to a given length.
|
static String |
repeat(String str,
int repeat)
Repeat a String
repeat times to form a
new String. |
static String |
repeat(String str,
String separator,
int repeat)
Repeat a String
repeat times to form a
new String, with a String separator injected each time. |
static String |
replace(String text,
String searchString,
String replacement)
Replaces all occurrences of a String within another String.
|
static String |
replace(String text,
String searchString,
String replacement,
int max)
Replaces a String with another String inside a larger String,
for the first
max values of the search String. |
static String[] |
split(String str,
char ch)
split.
|
static List<String> |
splitToList(String str,
char ch)
Splits String around matches of the given character.
|
static Set<String> |
splitToSet(String value,
char separatorChar)
Split the specified value to be a
Set |
static Set<String> |
splitToSet(String value,
char separatorChar,
boolean trimElements)
Split the specified value to be a
Set |
static String |
stripEnd(String str,
String stripChars)
Strips any of a set of characters from the end of a String.
|
static String |
toArgumentString(Object[] args) |
static String |
toCommaDelimitedString(String one,
String... others)
|
static String |
toOSStyleKey(String key) |
static String |
toQueryString(Map<String,String> ps) |
static String |
toString(String msg,
Throwable e) |
static String |
toString(Throwable e) |
static String[] |
toStringArray(Collection<String> collection) |
static String |
toURLKey(String key) |
static String |
translate(String src,
String from,
String to)
translate.
|
static String |
trim(String str) |
public static final String EMPTY_STRING
public static final int INDEX_NOT_FOUND
public static final String[] EMPTY_STRING_ARRAY
public static final char EQUAL_CHAR
public static final String EQUAL
public static final char AND_CHAR
public static final String AND
public static final char SEMICOLON_CHAR
public static final String SEMICOLON
public static final char QUESTION_MASK_CHAR
public static final String QUESTION_MASK
public static final char SLASH_CHAR
public static final String SLASH
public static final char HYPHEN_CHAR
public static final String HYPHEN
public static int length(CharSequence cs)
0 if the CharSequence is
null.cs - a CharSequence or null0 if the CharSequence is
null.public static String repeat(String str, int repeat)
Repeat a String repeat times to form a
new String.
StringUtils.repeat(null, 2) = null
StringUtils.repeat("", 0) = ""
StringUtils.repeat("", 2) = ""
StringUtils.repeat("a", 3) = "aaa"
StringUtils.repeat("ab", 2) = "abab"
StringUtils.repeat("a", -2) = ""
str - the String to repeat, may be nullrepeat - number of times to repeat str, negative treated as zeronull if null String inputpublic static String repeat(String str, String separator, int repeat)
Repeat a String repeat times to form a
new String, with a String separator injected each time.
StringUtils.repeat(null, null, 2) = null
StringUtils.repeat(null, "x", 2) = null
StringUtils.repeat("", null, 0) = ""
StringUtils.repeat("", "", 2) = ""
StringUtils.repeat("", "x", 3) = "xxx"
StringUtils.repeat("?", ", ", 3) = "?, ?, ?"
str - the String to repeat, may be nullseparator - the String to inject, may be nullrepeat - number of times to repeat str, negative treated as zeronull if null String inputpublic static String removeEnd(String str, String remove)
Removes a substring only if it is at the end of a source string, otherwise returns the source string.
A null source string will return null.
An empty ("") source string will return the empty string.
A null search string will return the source string.
StringUtils.removeEnd(null, *) = null
StringUtils.removeEnd("", *) = ""
StringUtils.removeEnd(*, null) = *
StringUtils.removeEnd("www.domain.com", ".com.") = "www.domain.com"
StringUtils.removeEnd("www.domain.com", ".com") = "www.domain"
StringUtils.removeEnd("www.domain.com", "domain") = "www.domain.com"
StringUtils.removeEnd("abc", "") = "abc"
str - the source String to search, may be nullremove - the String to search for and remove, may be nullnull if null String inputpublic static String repeat(char ch, int repeat)
Returns padding using the specified delimiter repeated to a given length.
StringUtils.repeat('e', 0) = ""
StringUtils.repeat('e', 3) = "eee"
StringUtils.repeat('e', -2) = ""
Note: this method doesn't not support padding with
Unicode Supplementary Characters
as they require a pair of chars to be represented.
If you are needing to support full I18N of your applications
consider using repeat(String, int) instead.
ch - character to repeatrepeat - number of times to repeat char, negative treated as zerorepeat(String, int)public static String stripEnd(String str, String stripChars)
Strips any of a set of characters from the end of a String.
A null input String returns null.
An empty string ("") input returns the empty string.
If the stripChars String is null, whitespace is
stripped as defined by Character.isWhitespace(char).
StringUtils.stripEnd(null, *) = null
StringUtils.stripEnd("", *) = ""
StringUtils.stripEnd("abc", "") = "abc"
StringUtils.stripEnd("abc", null) = "abc"
StringUtils.stripEnd(" abc", null) = " abc"
StringUtils.stripEnd("abc ", null) = "abc"
StringUtils.stripEnd(" abc ", null) = " abc"
StringUtils.stripEnd(" abcyx", "xyz") = " abc"
StringUtils.stripEnd("120.00", ".0") = "12"
str - the String to remove characters from, may be nullstripChars - the set of characters to remove, null treated as whitespacenull if null String inputpublic static String replace(String text, String searchString, String replacement)
Replaces all occurrences of a String within another String.
A null reference passed to this method is a no-op.
StringUtils.replace(null, *, *) = null
StringUtils.replace("", *, *) = ""
StringUtils.replace("any", null, *) = "any"
StringUtils.replace("any", *, null) = "any"
StringUtils.replace("any", "", *) = "any"
StringUtils.replace("aba", "a", null) = "aba"
StringUtils.replace("aba", "a", "") = "b"
StringUtils.replace("aba", "a", "z") = "zbz"
text - text to search and replace in, may be nullsearchString - the String to search for, may be nullreplacement - the String to replace it with, may be nullnull if null String inputreplace(String text, String searchString, String replacement, int max)public static String replace(String text, String searchString, String replacement, int max)
Replaces a String with another String inside a larger String,
for the first max values of the search String.
A null reference passed to this method is a no-op.
StringUtils.replace(null, *, *, *) = null
StringUtils.replace("", *, *, *) = ""
StringUtils.replace("any", null, *, *) = "any"
StringUtils.replace("any", *, null, *) = "any"
StringUtils.replace("any", "", *, *) = "any"
StringUtils.replace("any", *, *, 0) = "any"
StringUtils.replace("abaa", "a", null, -1) = "abaa"
StringUtils.replace("abaa", "a", "", -1) = "b"
StringUtils.replace("abaa", "a", "z", 0) = "abaa"
StringUtils.replace("abaa", "a", "z", 1) = "zbaa"
StringUtils.replace("abaa", "a", "z", 2) = "zbza"
StringUtils.replace("abaa", "a", "z", -1) = "zbzz"
text - text to search and replace in, may be nullsearchString - the String to search for, may be nullreplacement - the String to replace it with, may be nullmax - maximum number of values to replace, or -1 if no maximumnull if null String inputpublic static boolean isBlank(CharSequence cs)
public static boolean isEmpty(String str)
str - source string.public static boolean isNoneEmpty(String... ss)
Checks if the strings contain empty or null elements.
StringUtils.isNoneEmpty(null) = false
StringUtils.isNoneEmpty("") = false
StringUtils.isNoneEmpty(" ") = true
StringUtils.isNoneEmpty("abc") = true
StringUtils.isNoneEmpty("abc", "def") = true
StringUtils.isNoneEmpty("abc", null) = false
StringUtils.isNoneEmpty("abc", "") = false
StringUtils.isNoneEmpty("abc", " ") = true
ss - the strings to checktrue if all strings are not empty or nullpublic static boolean isAnyEmpty(String... ss)
Checks if the strings contain at least on empty or null element.
StringUtils.isAnyEmpty(null) = true
StringUtils.isAnyEmpty("") = true
StringUtils.isAnyEmpty(" ") = false
StringUtils.isAnyEmpty("abc") = false
StringUtils.isAnyEmpty("abc", "def") = false
StringUtils.isAnyEmpty("abc", null) = true
StringUtils.isAnyEmpty("abc", "") = true
StringUtils.isAnyEmpty("abc", " ") = false
ss - the strings to checktrue if at least one in the strings is empty or nullpublic static boolean isNotEmpty(String str)
str - source string.public static boolean isInteger(String str)
str - public static int parseInteger(String str)
public static boolean isJavaIdentifier(String s)
public static boolean isContains(String str, char ch)
public static boolean isNotContains(String str, char ch)
public static boolean isContains(String[] values, String value)
values - value - public static boolean isNumeric(String str, boolean allowDot)
public static String toString(String msg, Throwable e)
msg - e - public static String translate(String src, String from, String to)
src - source string.from - src char table.to - target char table.public static String[] split(String str, char ch)
ch - char.public static List<String> splitToList(String str, char ch)
Note: Compare with split(String, char), this method reduce memory copy.
public static Set<String> splitToSet(String value, char separatorChar)
Setvalue - the content to be splitseparatorChar - a char to separateSetpublic static Set<String> splitToSet(String value, char separatorChar, boolean trimElements)
Setvalue - the content to be splitseparatorChar - a char to separatetrimElements - require to trim the elements or notSetpublic static String join(String[] array)
array - String array.public static String join(String[] array, char split)
array - String array.split - splitpublic static String join(String[] array, String split)
array - String array.split - splitpublic static String join(Collection<String> coll, String split)
public static Map<String,String> parseQueryString(String qs)
qs - query string.public static boolean isAllUpperCase(String str)
public static String[] delimitedListToStringArray(String str, String delimiter)
public static String[] delimitedListToStringArray(String str, String delimiter, String charsToDelete)
public static String[] toStringArray(Collection<String> collection)
public static Map<String,String> parseParameters(String rawParameters)
rawParameters - format like '[{a:b},{c:d}]'public static int decodeHexNibble(char c)
public static byte decodeHexByte(CharSequence s, int pos)
Copyright © 2011–2022 The Apache Software Foundation. All rights reserved.