public final class ConvertUtil extends Object
| 限定符和类型 | 方法和说明 |
|---|---|
static String |
cleanText(String txt)
清理字符串,清理出某些不可见字符和一些sql特殊字符
|
static <T> Map<String,T> |
keyString2Map(String keyStr,
String separator,
T value)
字符转换为 Map 类型
|
static <T> void |
keyString2Map(String keyStr,
String separator,
T value,
Map<String,T> map)
字符转换为 Map 类型,比如:name=tom,age=18
|
static <T> Map<String,T> |
list2Map(List<String> list,
T value)
List 转换为 Map 类型,map 的 v 的值统一为 参数 value
|
static <T> void |
list2Map(List<String> list,
T value,
Map<String,T> map)
List 转换为 Map 类型,map 的 v 的值统一为 参数 value
|
static String[] |
split(String str,
String separatorChars,
int max)
Copy from
org.apache.commons.lang3.StringUtils
Splits the provided text into an array with a maximum length,
separators specified. |
static String[] |
splitByCharacterTypeCamelCase(String str,
boolean camelCase)
Copy from
org.apache.commons.lang3.StringUtils
Splits a String by Character type as returned by
java.lang.Character.getType(char). |
static Map<String,Object> |
string2JsonMap(String kvStrings,
String separator,
String kvSeparator)
字符转换为 Map 类型,比如:name=tom,age=18
当 kvStrings 为空时,返回空的 map
|
static List<String> |
string2List(String str,
String separator)
字符转换为 List 类型,比如:name,age,job
|
static Set<String> |
string2Set(String str,
String separator)
字符转换为 Set 类型,比如:name,age,job
|
@Nullable public static String cleanText(@Nullable String txt)
txt - 文本public static Set<String> string2Set(String str, String separator)
str - 字符串separator - 分隔符,不为 nullpublic static List<String> string2List(String str, String separator)
str - 字符串separator - 分隔符,不为 nullpublic static <T> Map<String,T> list2Map(List<String> list, T value)
list - 不为 nullvalue - map 的 value,不为 nullpublic static <T> void list2Map(List<String> list, T value, Map<String,T> map)
list - Listvalue - map 的 valuemap - 用于存储结果的 Mappublic static Map<String,Object> string2JsonMap(String kvStrings, String separator, String kvSeparator)
kvStrings - 字符串separator - 分隔符,不为 nullkvSeparator - key 与 value 的分隔符,不为 nullpublic static <T> Map<String,T> keyString2Map(String keyStr, String separator, T value)
keyStr - keyStr 格式:name,ageseparator - 分隔符, 如 ',',不为 nullvalue - map 的 value,不为 nullpublic static <T> void keyString2Map(String keyStr, String separator, T value, Map<String,T> map)
keyStr - keyStr 格式:name,ageseparator - 分隔符, 如 ',',不为 nullvalue - map 的 value,不为 nullmap - 用于存储结果的 Mappublic static String[] split(String str, String separatorChars, int max)
org.apache.commons.lang3.StringUtils
Splits the provided text into an array with a maximum length, separators specified.
The separator is not included in the returned String array. Adjacent separators are treated as one separator.
A null input String returns null.
A null separatorChars splits on whitespace.
If more than max delimited substrings are found, the last
returned string includes all characters after the first max - 1
returned strings (including separator characters).
StringUtils.split(null, *, *) = null
StringUtils.split("", *, *) = []
StringUtils.split("ab cd ef", null, 0) = ["ab", "cd", "ef"]
StringUtils.split("ab cd ef", null, 0) = ["ab", "cd", "ef"]
StringUtils.split("ab:cd:ef", ":", 0) = ["ab", "cd", "ef"]
StringUtils.split("ab:cd:ef", ":", 2) = ["ab", "cd:ef"]
str - the String to parse, may be nullseparatorChars - the characters used as the delimiters,
null splits on whitespacemax - the maximum number of elements to include in the
array. A zero or negative value implies no limitnull if null String inputpublic static String[] splitByCharacterTypeCamelCase(String str, boolean camelCase)
org.apache.commons.lang3.StringUtils
Splits a String by Character type as returned by
java.lang.Character.getType(char). Groups of contiguous
characters of the same type are returned as complete tokens, with the
following exception: the character of type
Character.UPPERCASE_LETTER, if any, immediately
preceding a token of type Character.LOWERCASE_LETTER
will belong to the following token rather than to the preceding, if any,
Character.UPPERCASE_LETTER token.
StringUtils.splitByCharacterTypeCamelCase(null) = null
StringUtils.splitByCharacterTypeCamelCase("") = []
StringUtils.splitByCharacterTypeCamelCase("ab de fg") = ["ab", " ", "de", " ", "fg"]
StringUtils.splitByCharacterTypeCamelCase("ab de fg") = ["ab", " ", "de", " ", "fg"]
StringUtils.splitByCharacterTypeCamelCase("ab:cd:ef") = ["ab", ":", "cd", ":", "ef"]
StringUtils.splitByCharacterTypeCamelCase("number5") = ["number", "5"]
StringUtils.splitByCharacterTypeCamelCase("fooBar") = ["foo", "Bar"]
StringUtils.splitByCharacterTypeCamelCase("foo200Bar") = ["foo", "200", "Bar"]
StringUtils.splitByCharacterTypeCamelCase("ASFRules") = ["ASF", "Rules"]
str - the String to split, may be nullcamelCase - whether to use so-called "camel-case" for letter typesnull if null String inputCopyright © 2021. All rights reserved.