类 StringUtils
- java.lang.Object
-
- org.apache.dubbo.common.utils.StringUtils
-
public final class StringUtils extends Object
StringUtils
-
-
字段概要
字段 修饰符和类型 字段 说明 static StringANDstatic charAND_CHARstatic StringEMPTY_STRINGstatic String[]EMPTY_STRING_ARRAYstatic StringEQUALstatic charEQUAL_CHARstatic StringHYPHENstatic charHYPHEN_CHARstatic intINDEX_NOT_FOUNDstatic StringQUESTION_MASKstatic charQUESTION_MASK_CHARstatic StringSEMICOLONstatic charSEMICOLON_CHARstatic StringSLASHstatic charSLASH_CHAR
-
方法概要
所有方法 静态方法 具体方法 修饰符和类型 方法 说明 static StringarrayToDelimitedString(Object[] arr, String delim)static StringcamelToSplitName(String camelName, String split)static StringconvertToSplitName(String str, String split)Convert camelCase or snake_case/SNAKE_CASE to kebab-casestatic bytedecodeHexByte(CharSequence s, int pos)Decode a 2-digit hex byte from within a string.static intdecodeHexNibble(char c)static StringdeleteAny(String inString, String charsToDelete)static String[]delimitedListToStringArray(String str, String delimiter)static String[]delimitedListToStringArray(String str, String delimiter, String charsToDelete)static StringencodeParameters(Map<String,String> params)Encode parameters map to string, like '[{a:b},{c:d}]'static StringgetQueryStringValue(String qs, String key)static StringgetServiceKey(Map<String,String> ps)static booleanhasText(CharSequence cs)Check the cs String whether contains non whitespace characters.static booleanisAllUpperCase(String str)static booleanisAnyEmpty(String... ss)Checks if the strings contain at least on empty or null element.static booleanisBlank(CharSequence cs)static booleanisContains(String[] values, String value)static booleanisContains(String str, char ch)static booleanisContains(String values, String value)static booleanisEmpty(String str)is empty string.static booleanisEquals(String s1, String s2)if s1 is null and s2 is null, then return truestatic booleanisJavaIdentifier(String s)Returns true if s is a legal Java identifier.static booleanisNoneEmpty(String... ss)Checks if the strings contain empty or null elements.static booleanisNotBlank(CharSequence cs)is not blank string.static booleanisNotContains(String str, char ch)static booleanisNotEmpty(String str)is not empty string.static booleanisNumber(String str)is positive integer or zero string.static booleanisNumeric(String str, boolean allowDot)static Stringjoin(String[] array)join string.static Stringjoin(String[] array, char split)join string like javascript.static Stringjoin(String[] array, String split)join string like javascript.static Stringjoin(Collection<String> coll, String split)static intlength(CharSequence cs)Gets a CharSequence length or0if the CharSequence isnull.static StringnullSafeToString(Object obj)static intparseInteger(String str)parse str to Integer(if str is not number or n < 0, then return 0)static longparseLong(String str)parse str to Long(if str is not number or n < 0, then return 0)static Map<String,String>parseParameters(String rawParameters)Decode parameters string to mapstatic Map<String,String>parseQueryString(String qs)parse query string to Parameters.static StringremoveEnd(String str, String remove)Removes a substring only if it is at the end of a source string, otherwise returns the source string.static Stringrepeat(char ch, int repeat)Returns padding using the specified delimiter repeated to a given length.static Stringrepeat(String str, int repeat)Repeat a Stringrepeattimes to form a new String.static Stringrepeat(String str, String separator, int repeat)Repeat a Stringrepeattimes to form a new String, with a String separator injected each time.static Stringreplace(String text, String searchString, String replacement)Replaces all occurrences of a String within another String.static Stringreplace(String text, String searchString, String replacement, int max)Replaces a String with another String inside a larger String, for the firstmaxvalues of the search String.static StringsnakeToSplitName(String snakeName, String split)Convert snake_case or SNAKE_CASE to kebab-case.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 aSetstatic Set<String>splitToSet(String value, char separatorChar, boolean trimElements)Split the specified value to be aSetstatic booleanstartsWithIgnoreCase(String str, String prefix)Test str whether starts with the prefix ignore case.static StringstripEnd(String str, String stripChars)Strips any of a set of characters from the end of a String.static StringtoArgumentString(Object[] args)static StringtoCommaDelimitedString(String one, String... others)static StringtoOSStyleKey(String key)static StringtoQueryString(Map<String,String> ps)static StringtoString(String msg, Throwable e)static StringtoString(Throwable e)static String[]toStringArray(Collection<String> collection)static StringtoURLKey(String key)static Stringtranslate(String src, String from, String to)translate.static Stringtrim(String str)
-
-
-
字段详细资料
-
INDEX_NOT_FOUND
public static final int INDEX_NOT_FOUND
- 另请参阅:
- 常量字段值
-
EMPTY_STRING_ARRAY
public static final String[] EMPTY_STRING_ARRAY
-
EQUAL_CHAR
public static final char EQUAL_CHAR
- 从以下版本开始:
- 2.7.5
- 另请参阅:
- 常量字段值
-
EQUAL
public static final String EQUAL
-
AND_CHAR
public static final char AND_CHAR
- 另请参阅:
- 常量字段值
-
AND
public static final String AND
-
SEMICOLON_CHAR
public static final char SEMICOLON_CHAR
- 另请参阅:
- 常量字段值
-
SEMICOLON
public static final String SEMICOLON
-
QUESTION_MASK_CHAR
public static final char QUESTION_MASK_CHAR
- 另请参阅:
- 常量字段值
-
QUESTION_MASK
public static final String QUESTION_MASK
-
SLASH_CHAR
public static final char SLASH_CHAR
- 另请参阅:
- 常量字段值
-
SLASH
public static final String SLASH
-
HYPHEN_CHAR
public static final char HYPHEN_CHAR
- 另请参阅:
- 常量字段值
-
HYPHEN
public static final String HYPHEN
-
-
方法详细资料
-
length
public static int length(CharSequence cs)
Gets a CharSequence length or0if the CharSequence isnull.- 参数:
cs- a CharSequence ornull- 返回:
- CharSequence length or
0if the CharSequence isnull.
-
repeat
public static String repeat(String str, int repeat)
Repeat a String
repeattimes 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 zero- 返回:
- a new String consisting of the original String repeated,
nullif null String input
-
repeat
public static String repeat(String str, String separator, int repeat)
Repeat a String
repeattimes 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 zero- 返回:
- a new String consisting of the original String repeated,
nullif null String input - 从以下版本开始:
- 2.5
-
removeEnd
public 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
nullsource string will returnnull. An empty ("") source string will return the empty string. Anullsearch 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 null- 返回:
- the substring with the string removed if found,
nullif null String input
-
repeat
public 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 usingrepeat(String, int)instead.- 参数:
ch- character to repeatrepeat- number of times to repeat char, negative treated as zero- 返回:
- String with repeated character
- 另请参阅:
repeat(String, int)
-
stripEnd
public static String stripEnd(String str, String stripChars)
Strips any of a set of characters from the end of a String.
A
nullinput String returnsnull. An empty string ("") input returns the empty string.If the stripChars String is
null, whitespace is stripped as defined byCharacter.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 whitespace- 返回:
- the stripped String,
nullif null String input
-
replace
public static String replace(String text, String searchString, String replacement)
Replaces all occurrences of a String within another String.
A
nullreference 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 null- 返回:
- the text with any replacements processed,
nullif null String input - 另请参阅:
replace(String text, String searchString, String replacement, int max)
-
replace
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
maxvalues of the search String.A
nullreference 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-1if no maximum- 返回:
- the text with any replacements processed,
nullif null String input
-
isBlank
public static boolean isBlank(CharSequence cs)
-
isNotBlank
public static boolean isNotBlank(CharSequence cs)
is not blank string.- 参数:
cs- source string.- 返回:
- is not blank.
-
hasText
public static boolean hasText(CharSequence cs)
Check the cs String whether contains non whitespace characters.- 参数:
cs-- 返回:
-
isEmpty
public static boolean isEmpty(String str)
is empty string.- 参数:
str- source string.- 返回:
- is empty.
-
isNoneEmpty
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 check- 返回:
trueif all strings are not empty or null
-
isAnyEmpty
public 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 check- 返回:
trueif at least one in the strings is empty or null
-
isNotEmpty
public static boolean isNotEmpty(String str)
is not empty string.- 参数:
str- source string.- 返回:
- is not empty.
-
isEquals
public static boolean isEquals(String s1, String s2)
if s1 is null and s2 is null, then return true- 参数:
s1- str1s2- str2- 返回:
- equals
-
isNumber
public static boolean isNumber(String str)
is positive integer or zero string.- 参数:
str- a string- 返回:
- is positive integer or zero
-
parseInteger
public static int parseInteger(String str)
parse str to Integer(if str is not number or n < 0, then return 0)- 参数:
str- a number str- 返回:
- positive integer or zero
-
parseLong
public static long parseLong(String str)
parse str to Long(if str is not number or n < 0, then return 0)- 参数:
str- a number str- 返回:
- positive long or zero
-
isJavaIdentifier
public static boolean isJavaIdentifier(String s)
Returns true if s is a legal Java identifier.
-
isContains
public static boolean isContains(String str, char ch)
-
isNotContains
public static boolean isNotContains(String str, char ch)
-
isContains
public static boolean isContains(String[] values, String value)
- 参数:
values-value-- 返回:
- contains
-
isNumeric
public static boolean isNumeric(String str, boolean allowDot)
-
translate
public static String translate(String src, String from, String to)
translate.- 参数:
src- source string.from- src char table.to- target char table.- 返回:
- String.
-
splitToList
public static List<String> splitToList(String str, char ch)
Splits String around matches of the given character.Note: Compare with
split(String, char), this method reduce memory copy.
-
splitToSet
public static Set<String> splitToSet(String value, char separatorChar)
Split the specified value to be aSet- 参数:
value- the content to be splitseparatorChar- a char to separate- 返回:
- non-null read-only
Set - 从以下版本开始:
- 2.7.8
-
splitToSet
public static Set<String> splitToSet(String value, char separatorChar, boolean trimElements)
Split the specified value to be aSet- 参数:
value- the content to be splitseparatorChar- a char to separatetrimElements- require to trim the elements or not- 返回:
- non-null read-only
Set - 从以下版本开始:
- 2.7.8
-
join
public static String join(String[] array, char split)
join string like javascript.- 参数:
array- String array.split- split- 返回:
- String.
-
join
public static String join(String[] array, String split)
join string like javascript.- 参数:
array- String array.split- split- 返回:
- String.
-
join
public static String join(Collection<String> coll, String split)
-
parseQueryString
public static Map<String,String> parseQueryString(String qs)
parse query string to Parameters.- 参数:
qs- query string.- 返回:
- Parameters instance.
-
snakeToSplitName
public static String snakeToSplitName(String snakeName, String split)
Convert snake_case or SNAKE_CASE to kebab-case.NOTE: Return itself if it's not a snake case.
- 参数:
snakeName-split-- 返回:
-
convertToSplitName
public static String convertToSplitName(String str, String split)
Convert camelCase or snake_case/SNAKE_CASE to kebab-case- 参数:
str-split-- 返回:
-
isAllUpperCase
public static boolean isAllUpperCase(String str)
-
delimitedListToStringArray
public static String[] delimitedListToStringArray(String str, String delimiter)
-
delimitedListToStringArray
public static String[] delimitedListToStringArray(String str, String delimiter, String charsToDelete)
-
toStringArray
public static String[] toStringArray(Collection<String> collection)
-
parseParameters
public static Map<String,String> parseParameters(String rawParameters)
Decode parameters string to map- 参数:
rawParameters- format like '[{a:b},{c:d}]'- 返回:
-
encodeParameters
public static String encodeParameters(Map<String,String> params)
Encode parameters map to string, like '[{a:b},{c:d}]'- 参数:
params-- 返回:
-
decodeHexNibble
public static int decodeHexNibble(char c)
-
decodeHexByte
public static byte decodeHexByte(CharSequence s, int pos)
Decode a 2-digit hex byte from within a string.
-
-