public class CharsKit extends Object
| Constructor and Description |
|---|
CharsKit() |
| Modifier and Type | Method and Description |
|---|---|
static char |
byteToChar(byte[] b)
byte转car
|
static int |
compare(char x,
char y)
对两个
char值进行数值比较 |
static int |
count(CharSequence content,
char charForSearch)
统计指定内容中包含指定字符的数量
|
static int |
count(CharSequence content,
CharSequence strForSearch)
统计指定内容中包含指定字符串的数量
参数为 null 或者 "" 返回 0. |
static boolean |
equals(char c1,
char c2,
boolean ignoreCase)
比较两个字符是否相同
|
static char[] |
getChars(byte[] bytes) |
static boolean |
hasBlank(CharSequence... texts)
指定字符串数组中,是否包含空字符串
如果指定的字符串数组的长度为 0,或者其中的任意一个元素是空字符串,则返回 true
例:
StringKit.hasBlank() // true
StringKit.hasBlank("", null, " ") // true
StringKit.hasBlank("123", " ") // true
StringKit.hasBlank("123", "abc") // false
注意:该方法与 isAllBlank(CharSequence...) 的区别在于:
hasBlank(CharSequence...) 等价于 isBlank(...) || isBlank(...) || ...
isAllBlank(CharSequence...) 等价于 isBlank(...) && isBlank(...) && ...
|
static boolean |
hasEmpty(CharSequence... texts)
是否包含空字符串
如果指定的字符串数组的长度为 0,或者其中的任意一个元素是空字符串,则返回 true
例:
StringKit.hasEmpty() // true
StringKit.hasEmpty("", null) // true
StringKit.hasEmpty("123", "") // true
StringKit.hasEmpty("123", "abc") // false
StringKit.hasEmpty(" ", "\t", "\n") // false
注意:该方法与 isAllEmpty(CharSequence...) 的区别在于:
hasEmpty(CharSequence...) 等价于 isEmpty(...) || isEmpty(...) || ...
isAllEmpty(CharSequence...) 等价于 isEmpty(...) && isEmpty(...) && ...
|
static boolean |
isAllBlank(CharSequence... texts)
指定字符串数组中的元素,是否全部为空字符串
如果指定的字符串数组的长度为 0,或者所有元素都是空字符串,则返回 true
例:
StringKit.isAllBlank() // true
StringKit.isAllBlank("", null, " ") // true
StringKit.isAllBlank("123", " ") // false
StringKit.isAllBlank("123", "abc") // false
注意:该方法与 hasBlank(CharSequence...) 的区别在于:
hasBlank(CharSequence...) 等价于 isBlank(...) || isBlank(...) || ...
isAllBlank(CharSequence...) 等价于 isBlank(...) && isBlank(...) && ...
|
static boolean |
isAllEmpty(CharSequence... texts)
指定字符串数组中的元素,是否全部为空字符串
如果指定的字符串数组的长度为 0,或者所有元素都是空字符串,则返回 true
例:
StringKit.isAllEmpty() // true
StringKit.isAllEmpty("", null) // true
StringKit.isAllEmpty("123", "") // false
StringKit.isAllEmpty("123", "abc") // false
StringKit.isAllEmpty(" ", "\t", "\n") // false
注意:该方法与 hasEmpty(CharSequence...) 的区别在于:
hasEmpty(CharSequence...) 等价于 isEmpty(...) || isEmpty(...) || ...
isAllEmpty(CharSequence...) 等价于 isEmpty(...) && isEmpty(...) && ...
|
static boolean |
isAllNotBlank(CharSequence... args)
是否存都不为
null或空对象或空白符的对象,通过hasBlank(CharSequence...) 判断元素 |
static boolean |
isAllNotEmpty(CharSequence... args)
指定字符串数组中的元素,是否都不为空字符串
如果指定的字符串数组的长度不为 0,或者所有元素都不是空字符串,则返回 true
例:
StringKit.isAllNotEmpty() // false
StringKit.isAllNotEmpty("", null) // false
StringKit.isAllNotEmpty("123", "") // false
StringKit.isAllNotEmpty("123", "abc") // true
StringKit.isAllNotEmpty(" ", "\t", "\n") // true
注意:该方法与 isAllEmpty(CharSequence...) 的区别在于:
isAllEmpty(CharSequence...) 等价于 isEmpty(...) && isEmpty(...) && ...
isAllNotEmpty(CharSequence...) 等价于 !isEmpty(...) && !isEmpty(...) && ...
|
static boolean |
isAscii(char ch)
是否为ASCII字符,ASCII字符位于0~127之间
|
static boolean |
isAsciiControl(char ch)
是否为ASCII控制符(不可见字符),控制符位于0~31和127
|
static boolean |
isAsciiPrintable(char ch)
是否为可见ASCII字符,可见字符位于32~126之间
|
static boolean |
isBlank(CharSequence text)
字符串是否为空白,空白的定义如下:
null
空字符串:""
空格、全角空格、制表符、换行符,等不可见字符
例:
StringKit.isBlank(null) // true
StringKit.isBlank("") // true
StringKit.isBlank(" \t\n") // true
StringKit.isBlank("abc") // false
注意:该方法与 isEmpty(CharSequence) 的区别是:
该方法会校验空白字符,且性能相对于 isEmpty(CharSequence) 略慢
建议:
该方法建议仅对于客户端(或第三方接口)传入的参数使用该方法。
需要同时校验多个字符串时,建议采用 hasBlank(CharSequence...) 或 isAllBlank(CharSequence...)
|
static boolean |
isBlankChar(char c)
是否空白符
空白符包括空格、制表符、全角空格和不间断空格
|
static boolean |
isBlankChar(int c)
是否空白符
空白符包括空格、制表符、全角空格和不间断空格
|
static boolean |
isBlankOrUndefined(CharSequence text)
检查字符串是否为null、空白串、“null”、“undefined”
|
static boolean |
isChar(Object value)
给定对象对应的类是否为字符类,字符类包括:
|
static boolean |
isCharClass(Class<?> clazz)
给定类名是否为字符类,字符类包括:
|
static boolean |
isEmoji(char c)
判断是否为emoji表情符
|
static boolean |
isEmpty(CharSequence text)
字符串是否为空,空的定义如下:
null
空字符串:""
例:
StringKit.isEmpty(null) // true
StringKit.isEmpty("") // true
StringKit.isEmpty(" \t\n") // false
StringKit.isEmpty("abc") // false
注意:该方法与 isBlank(CharSequence) 的区别是:该方法不校验空白字符
建议:
该方法建议用于工具类或任何可以预期的方法参数的校验中
需要同时校验多个字符串时,建议采用 hasEmpty(CharSequence...) 或 isAllEmpty(CharSequence...)
|
static boolean |
isEmptyOrUndefined(CharSequence text)
检查字符串是否为null、“”、“null”、“undefined”
|
static boolean |
isFileSeparator(char c)
是否为Windows或者Linux(Unix)文件分隔符
Windows平台下分隔符为\,Linux(Unix)为/
|
static boolean |
isHexChar(char c)
是否为16进制规范的字符,判断是否为如下字符
|
static boolean |
isLetter(char ch)
判断是否为字母(包括大写字母和小写字母)
字母包括A~Z和a~z
|
static boolean |
isLetterLower(char ch)
检查字符是否为小写字母,小写字母指a~z
|
static boolean |
isLetterOrNumber(char ch)
是否为字母或数字,包括A~Z、a~z、0~9
|
static boolean |
isLetterUpper(char ch)
判断是否为大写字母,大写字母包括A~Z
|
static boolean |
isNotBlank(CharSequence text)
字符串是否为非空白,非空白的定义如下:
不为
null
不为空字符串:""
不为空格、全角空格、制表符、换行符,等不可见字符
例:
StringKit.isNotBlank(null) // false
StringKit.isNotBlank("") // false
StringKit.isNotBlank(" \t\n") // false
StringKit.isNotBlank("abc") // true
注意:该方法与 isNotEmpty(CharSequence) 的区别是:
该方法会校验空白字符,且性能相对于 isNotEmpty(CharSequence) 略慢
建议:仅对于客户端(或第三方接口)传入的参数使用该方法 |
static boolean |
isNotEmpty(CharSequence text)
字符串是否为非空白,非空白的定义如下:
不为
null
不为空字符串:""
例:
StringKit.isNotEmpty(null) // false
StringKit.isNotEmpty("") // false
StringKit.isNotEmpty(" \t\n") // true
StringKit.isNotEmpty("abc") // true
注意:该方法与 isNotBlank(CharSequence) 的区别是:该方法不校验空白字符
建议:该方法建议用于工具类或任何可以预期的方法参数的校验中 |
static boolean |
isNullOrUndefined(CharSequence text)
检查字符串是否为null、“null”、“undefined”
|
static boolean |
isNumber(char ch)
检查是否为数字字符,数字字符指0~9
|
static boolean |
startWithChinese(CharSequence text)
字符串是否以(中文汉字)开始
|
static boolean |
startWithGeneral(CharSequence text)
字符串是否以(英文字母 、数字和下划线)开始
|
static boolean |
startWithNumber(CharSequence text)
字符串是否以(数字)开始
|
static boolean |
startWithWord(CharSequence text)
字符串是否以(字母)开始
|
static char |
toCloseByNumber(int number)
封闭式字符,英文:Enclosed Alphanumerics
将[1-20]数字转换为带圈的字符:
|
static char |
toCloseChar(char c)
将字母、数字转换为带圈的字符:
|
static String |
toString(char c)
字符转为字符串
如果为ASCII字符,使用缓存
|
public static boolean isAscii(char ch)
CharKit.isAscii('a') = true
CharKit.isAscii('A') = true
CharKit.isAscii('3') = true
CharKit.isAscii('-') = true
CharKit.isAscii('\n') = true
CharKit.isAscii('©') = false
ch - 被检查的字符处public static boolean isAsciiPrintable(char ch)
CharKit.isAsciiPrintable('a') = true
CharKit.isAsciiPrintable('A') = true
CharKit.isAsciiPrintable('3') = true
CharKit.isAsciiPrintable('-') = true
CharKit.isAsciiPrintable('\n') = false
CharKit.isAsciiPrintable('©') = false
ch - 被检查的字符处public static boolean isAsciiControl(char ch)
CharKit.isAsciiControl('a') = false
CharKit.isAsciiControl('A') = false
CharKit.isAsciiControl('3') = false
CharKit.isAsciiControl('-') = false
CharKit.isAsciiControl('\n') = true
CharKit.isAsciiControl('©') = false
ch - 被检查的字符public static boolean isLetter(char ch)
CharKit.isLetter('a') = true
CharKit.isLetter('A') = true
CharKit.isLetter('3') = false
CharKit.isLetter('-') = false
CharKit.isLetter('\n') = false
CharKit.isLetter('©') = false
ch - 被检查的字符public static boolean isLetterUpper(char ch)
CharKit.isLetterUpper('a') = false
CharKit.isLetterUpper('A') = true
CharKit.isLetterUpper('3') = false
CharKit.isLetterUpper('-') = false
CharKit.isLetterUpper('\n') = false
CharKit.isLetterUpper('©') = false
ch - 被检查的字符public static boolean isLetterLower(char ch)
CharKit.isLetterLower('a') = true
CharKit.isLetterLower('A') = false
CharKit.isLetterLower('3') = false
CharKit.isLetterLower('-') = false
CharKit.isLetterLower('\n') = false
CharKit.isLetterLower('©') = false
ch - 被检查的字符public static boolean isNumber(char ch)
CharKit.isNumber('a') = false
CharKit.isNumber('A') = false
CharKit.isNumber('3') = true
CharKit.isNumber('-') = false
CharKit.isNumber('\n') = false
CharKit.isNumber('©') = false
ch - 被检查的字符public static boolean isHexChar(char c)
1. 0~9 2. a~f 4. A~F
c - 字符public static boolean isLetterOrNumber(char ch)
CharKit.isLetterOrNumber('a') = true
CharKit.isLetterOrNumber('A') = true
CharKit.isLetterOrNumber('3') = true
CharKit.isLetterOrNumber('-') = false
CharKit.isLetterOrNumber('\n') = false
CharKit.isLetterOrNumber('©') = false
ch - 被检查的字符public static boolean isCharClass(Class<?> clazz)
Character.class char.class
clazz - 被检查的类public static boolean isChar(Object value)
Character.class char.class
value - 被检查的对象public static boolean isBlankChar(char c)
c - 字符Character.isWhitespace(int),
Character.isSpaceChar(int)public static boolean isBlankChar(int c)
c - 字符Character.isWhitespace(int),
Character.isSpaceChar(int)public static boolean isBlank(CharSequence text)
null""StringKit.isBlank(null) // trueStringKit.isBlank("") // trueStringKit.isBlank(" \t\n") // trueStringKit.isBlank("abc") // falseisEmpty(CharSequence) 的区别是:
该方法会校验空白字符,且性能相对于 isEmpty(CharSequence) 略慢
建议:
hasBlank(CharSequence...) 或 isAllBlank(CharSequence...)text - 被检测的字符串isEmpty(CharSequence)public static boolean isNotBlank(CharSequence text)
null""StringKit.isNotBlank(null) // falseStringKit.isNotBlank("") // falseStringKit.isNotBlank(" \t\n") // falseStringKit.isNotBlank("abc") // trueisNotEmpty(CharSequence) 的区别是:
该方法会校验空白字符,且性能相对于 isNotEmpty(CharSequence) 略慢
建议:仅对于客户端(或第三方接口)传入的参数使用该方法text - 被检测的字符串isBlank(CharSequence)public static boolean isAllBlank(CharSequence... texts)
StringKit.isAllBlank() // trueStringKit.isAllBlank("", null, " ") // trueStringKit.isAllBlank("123", " ") // falseStringKit.isAllBlank("123", "abc") // falsehasBlank(CharSequence...) 的区别在于:
hasBlank(CharSequence...) 等价于 isBlank(...) || isBlank(...) || ...isBlank(...) && isBlank(...) && ...texts - 字符串列表public static boolean isEmpty(CharSequence text)
null""StringKit.isEmpty(null) // trueStringKit.isEmpty("") // trueStringKit.isEmpty(" \t\n") // falseStringKit.isEmpty("abc") // falseisBlank(CharSequence) 的区别是:该方法不校验空白字符
建议:
hasEmpty(CharSequence...) 或 isAllEmpty(CharSequence...)text - 被检测的字符串isBlank(CharSequence)public static boolean isNotEmpty(CharSequence text)
null""StringKit.isNotEmpty(null) // falseStringKit.isNotEmpty("") // falseStringKit.isNotEmpty(" \t\n") // trueStringKit.isNotEmpty("abc") // trueisNotBlank(CharSequence) 的区别是:该方法不校验空白字符
建议:该方法建议用于工具类或任何可以预期的方法参数的校验中text - 被检测的字符串isEmpty(CharSequence)public static boolean isAllEmpty(CharSequence... texts)
StringKit.isAllEmpty() // trueStringKit.isAllEmpty("", null) // trueStringKit.isAllEmpty("123", "") // falseStringKit.isAllEmpty("123", "abc") // falseStringKit.isAllEmpty(" ", "\t", "\n") // falsehasEmpty(CharSequence...) 的区别在于:
hasEmpty(CharSequence...) 等价于 isEmpty(...) || isEmpty(...) || ...isEmpty(...) && isEmpty(...) && ...texts - 字符串列表public static boolean isAllNotEmpty(CharSequence... args)
StringKit.isAllNotEmpty() // falseStringKit.isAllNotEmpty("", null) // falseStringKit.isAllNotEmpty("123", "") // falseStringKit.isAllNotEmpty("123", "abc") // trueStringKit.isAllNotEmpty(" ", "\t", "\n") // trueisAllEmpty(CharSequence...) 的区别在于:
isAllEmpty(CharSequence...) 等价于 isEmpty(...) && isEmpty(...) && ...!isEmpty(...) && !isEmpty(...) && ...args - 字符串数组public static boolean isAllNotBlank(CharSequence... args)
null或空对象或空白符的对象,通过hasBlank(CharSequence...) 判断元素args - 被检查的对象,一个或者多个public static boolean isNullOrUndefined(CharSequence text)
text - 被检查的字符串public static boolean isEmptyOrUndefined(CharSequence text)
text - 被检查的字符串public static boolean isBlankOrUndefined(CharSequence text)
text - 被检查的字符串public static boolean hasBlank(CharSequence... texts)
StringKit.hasBlank() // trueStringKit.hasBlank("", null, " ") // trueStringKit.hasBlank("123", " ") // trueStringKit.hasBlank("123", "abc") // falseisAllBlank(CharSequence...) 的区别在于:
isBlank(...) || isBlank(...) || ...isAllBlank(CharSequence...) 等价于 isBlank(...) && isBlank(...) && ...texts - 字符串列表public static boolean hasEmpty(CharSequence... texts)
StringKit.hasEmpty() // trueStringKit.hasEmpty("", null) // trueStringKit.hasEmpty("123", "") // trueStringKit.hasEmpty("123", "abc") // falseStringKit.hasEmpty(" ", "\t", "\n") // falseisAllEmpty(CharSequence...) 的区别在于:
isEmpty(...) || isEmpty(...) || ...isAllEmpty(CharSequence...) 等价于 isEmpty(...) && isEmpty(...) && ...texts - 字符串列表public static boolean isEmoji(char c)
c - 字符public static boolean equals(char c1,
char c2,
boolean ignoreCase)
c1 - 字符1c2 - 字符2ignoreCase - 是否忽略大小写public static int count(CharSequence content, CharSequence strForSearch)
null 或者 "" 返回 0.
count(null, *) = 0
count("", *) = 0
count("abba", null) = 0
count("abba", "") = 0
count("abba", "a") = 2
count("abba", "ab") = 1
count("abba", "xxx") = 0
content - 被查找的字符串strForSearch - 需要查找的字符串public static int count(CharSequence content, char charForSearch)
content - 内容charForSearch - 被统计的字符public static String toString(char c)
c - 字符public static boolean isFileSeparator(char c)
c - 字符public static int compare(char x,
char y)
char值进行数值比较x - chary - char
如果x == y返回值0;
如果x < y值小于0;和
如果x > ypublic static char[] getChars(byte[] bytes)
public static char byteToChar(byte[] b)
b - 字节信息public static char toCloseChar(char c)
'1' -》 '①'
'A' -》 'Ⓐ'
'a' -》 'ⓐ'
获取带圈数字 /封闭式字母数字 ,从1-20,超过1-20报错
0 1 2 3 4 5 6 7 8 9 A B C D E F
U+246x ① ② ③ ④ ⑤ ⑥ ⑦ ⑧ ⑨ ⑩ ⑪ ⑫ ⑬ ⑭ ⑮ ⑯
U+247x ⑰ ⑱ ⑲ ⑳ ⑴ ⑵ ⑶ ⑷ ⑸ ⑹ ⑺ ⑻ ⑼ ⑽ ⑾ ⑿
U+248x ⒀ ⒁ ⒂ ⒃ ⒄ ⒅ ⒆ ⒇ ⒈ ⒉ ⒊ ⒋ ⒌ ⒍ ⒎ ⒏
U+249x ⒐ ⒑ ⒒ ⒓ ⒔ ⒕ ⒖ ⒗ ⒘ ⒙ ⒚ ⒛ ⒜ ⒝ ⒞ ⒟
U+24Ax ⒠ ⒡ ⒢ ⒣ ⒤ ⒥ ⒦ ⒧ ⒨ ⒩ ⒪ ⒫ ⒬ ⒭ ⒮ ⒯
U+24Bx ⒰ ⒱ ⒲ ⒳ ⒴ ⒵ Ⓐ Ⓑ Ⓒ Ⓓ Ⓔ Ⓕ Ⓖ Ⓗ Ⓘ Ⓙ
U+24Cx Ⓚ Ⓛ Ⓜ Ⓝ Ⓞ Ⓟ Ⓠ Ⓡ Ⓢ Ⓣ Ⓤ Ⓥ Ⓦ Ⓧ Ⓨ Ⓩ
U+24Dx ⓐ ⓑ ⓒ ⓓ ⓔ ⓕ ⓖ ⓗ ⓘ ⓙ ⓚ ⓛ ⓜ ⓝ ⓞ ⓟ
U+24Ex ⓠ ⓡ ⓢ ⓣ ⓤ ⓥ ⓦ ⓧ ⓨ ⓩ ⓪ ⓫ ⓬ ⓭ ⓮ ⓯
U+24Fx ⓰ ⓱ ⓲ ⓳ ⓴ ⓵ ⓶ ⓷ ⓸ ⓹ ⓺ ⓻ ⓼ ⓽ ⓾ ⓿c - 被转换的字符,如果字符不支持转换,返回原字符public static char toCloseByNumber(int number)
1 -》 '①'
12 -》 '⑫'
20 -》 '⑳'
number - 被转换的数字public static boolean startWithNumber(CharSequence text)
text - 字符串public static boolean startWithGeneral(CharSequence text)
text - 字符串public static boolean startWithWord(CharSequence text)
text - 字符串public static boolean startWithChinese(CharSequence text)
text - 字符串Copyright © 2021. All rights reserved.