public final class StringUtils extends Object
| 限定符和类型 | 字段和说明 |
|---|---|
static String |
EMPTY |
static String[] |
EMPTY_STRING_ARRAY |
static int |
INDEX_NOT_FOUND |
| 限定符和类型 | 方法和说明 |
|---|---|
static String |
camelToSplitName(String camelName,
String split) |
static String |
getQueryStringValue(String qs,
String key) |
static String |
getServiceKey(Map<String,String> ps) |
static boolean |
isAnyEmpty(String... ss)
Checks if the strings contain at least on empty or null element.
|
static boolean |
isBlank(String str) |
static boolean |
isContains(String[] values,
String value) |
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 |
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 int |
parseInteger(String str) |
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 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 |
toQueryString(Map<String,String> ps) |
static String |
toString(String msg,
Throwable e) |
static String |
toString(Throwable e) |
static String |
translate(String src,
String from,
String to)
translate.
|
static String |
trim(String str) |
public static final int INDEX_NOT_FOUND
public static final String[] EMPTY_STRING_ARRAY
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(String str)
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[] values, String value)
values - value - public static boolean isNumeric(String str, boolean allowDot)
public static String translate(String src, String from, String to)
src - source string.from - src char table.to - target char table.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.Copyright © 2011–2019 The Apache Software Foundation. All rights reserved.