public class StrValidator extends Object
null or 空字符串:""null or 空字符串:"" or 空格、全角空格、制表符、换行符,等不可见字符| Modifier and Type | Field and Description |
|---|---|
static String |
EMPTY
字符串常量:空字符串
"" |
static String |
NULL
字符串常量:
"null" 注意:{@code "null" ! |
| Constructor and Description |
|---|
StrValidator() |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
hasBlank(CharSequence... strs)
指定字符串数组中,是否包含空字符串。
|
static boolean |
hasEmpty(CharSequence... strs)
是否包含空字符串。
|
static boolean |
hasEmpty(Iterable<? extends CharSequence> strs)
是否包含空字符串。
|
static boolean |
isAllBlank(CharSequence... strs)
指定字符串数组中的元素,是否全部为空字符串。
|
static boolean |
isAllCharMatch(CharSequence value,
Predicate<Character> matcher)
字符串的每一个字符是否都与定义的匹配器匹配
|
static boolean |
isAllEmpty(CharSequence... strs)
指定字符串数组中的元素,是否全部为空字符串。
|
static boolean |
isAllEmpty(Iterable<? extends CharSequence> strs)
指定字符串数组中的元素,是否全部为空字符串。
|
static boolean |
isAllNotBlank(CharSequence... args)
是否存都不为
null或空对象或空白符的对象,通过hasBlank(CharSequence...) |
static boolean |
isAllNotEmpty(CharSequence... args)
指定字符串数组中的元素,是否都不为空字符串。
|
static boolean |
isBlank(CharSequence str)
字符串是否为空白,空白的定义如下:
null
空字符串:""
空格、全角空格、制表符、换行符,等不可见字符
例:
StrUtil.isBlank(null) // true
StrUtil.isBlank("") // true
StrUtil.isBlank(" \t\n") // true
StrUtil.isBlank("abc") // false
注意:该方法与 isEmpty(CharSequence) 的区别是:
该方法会校验空白字符,且性能相对于 isEmpty(CharSequence) 略慢。 |
static boolean |
isBlankOrUndefined(CharSequence str)
检查字符串是否为null、空白串、“null”、“undefined”
|
static boolean |
isEmpty(CharSequence str)
字符串是否为空,空的定义如下:
null
空字符串:""
例:
StrUtil.isEmpty(null) // true
StrUtil.isEmpty("") // true
StrUtil.isEmpty(" \t\n") // false
StrUtil.isEmpty("abc") // false
注意:该方法与 isBlank(CharSequence) 的区别是:该方法不校验空白字符。 |
static boolean |
isEmptyOrUndefined(CharSequence str)
检查字符串是否为null、“”、“null”、“undefined”
|
static boolean |
isNotBlank(CharSequence str)
字符串是否为非空白,非空白的定义如下:
不为
null
不为空字符串:""
不为空格、全角空格、制表符、换行符,等不可见字符
例:
StrUtil.isNotBlank(null) // false
StrUtil.isNotBlank("") // false
StrUtil.isNotBlank(" \t\n") // false
StrUtil.isNotBlank("abc") // true
注意:该方法与 isNotEmpty(CharSequence) 的区别是:
该方法会校验空白字符,且性能相对于 isNotEmpty(CharSequence) 略慢。 |
static boolean |
isNotEmpty(CharSequence str)
字符串是否为非空白,非空白的定义如下:
不为
null
不为空字符串:""
例:
StrUtil.isNotEmpty(null) // false
StrUtil.isNotEmpty("") // false
StrUtil.isNotEmpty(" \t\n") // true
StrUtil.isNotEmpty("abc") // true
注意:该方法与 isNotBlank(CharSequence) 的区别是:该方法不校验空白字符。 |
static boolean |
isNullOrUndefined(CharSequence str)
检查字符串是否为null、“null”、“undefined”
|
public static final String NULL
"null" "null" != nullpublic static final String EMPTY
""public static boolean isBlank(CharSequence str)
字符串是否为空白,空白的定义如下:
null""例:
StrUtil.isBlank(null) // trueStrUtil.isBlank("") // trueStrUtil.isBlank(" \t\n") // trueStrUtil.isBlank("abc") // false注意:该方法与 isEmpty(CharSequence) 的区别是:
该方法会校验空白字符,且性能相对于 isEmpty(CharSequence) 略慢。
建议:
ArrayUtil.hasBlank(CharSequence...) 或 ArrayUtil.isAllBlank(CharSequence...)str - 被检测的字符串isEmpty(CharSequence)public static boolean isNotBlank(CharSequence str)
字符串是否为非空白,非空白的定义如下:
null""例:
StrUtil.isNotBlank(null) // falseStrUtil.isNotBlank("") // falseStrUtil.isNotBlank(" \t\n") // falseStrUtil.isNotBlank("abc") // true注意:该方法与 isNotEmpty(CharSequence) 的区别是:
该方法会校验空白字符,且性能相对于 isNotEmpty(CharSequence) 略慢。
建议:仅对于客户端(或第三方接口)传入的参数使用该方法。
str - 被检测的字符串isBlank(CharSequence)public static boolean isEmpty(CharSequence str)
字符串是否为空,空的定义如下:
null""例:
StrUtil.isEmpty(null) // trueStrUtil.isEmpty("") // trueStrUtil.isEmpty(" \t\n") // falseStrUtil.isEmpty("abc") // false注意:该方法与 isBlank(CharSequence) 的区别是:该方法不校验空白字符。
建议:
hasEmpty(CharSequence...) 或 isAllEmpty(CharSequence...)str - 被检测的字符串isBlank(CharSequence)public static boolean isNotEmpty(CharSequence str)
字符串是否为非空白,非空白的定义如下:
null""例:
StrUtil.isNotEmpty(null) // falseStrUtil.isNotEmpty("") // falseStrUtil.isNotEmpty(" \t\n") // trueStrUtil.isNotEmpty("abc") // true注意:该方法与 isNotBlank(CharSequence) 的区别是:该方法不校验空白字符。
建议:该方法建议用于工具类或任何可以预期的方法参数的校验中。
str - 被检测的字符串isEmpty(CharSequence)public static boolean hasBlank(CharSequence... strs)
指定字符串数组中,是否包含空字符串。
如果指定的字符串数组的长度为 0,或者其中的任意一个元素是空字符串,则返回 true。
例:
hasBlank() // truehasBlank("", null, " ") // truehasBlank("123", " ") // truehasBlank("123", "abc") // false注意:该方法与 isAllBlank(CharSequence...) 的区别在于:
isBlank(...) || isBlank(...) || ...isAllBlank(CharSequence...) 等价于 isBlank(...) && isBlank(...) && ...strs - 字符串列表public static boolean isAllNotBlank(CharSequence... args)
null或空对象或空白符的对象,通过hasBlank(CharSequence...) 判断元素args - 被检查的对象,一个或者多个public static boolean isAllBlank(CharSequence... strs)
指定字符串数组中的元素,是否全部为空字符串。
如果指定的字符串数组的长度为 0,或者所有元素都是空字符串,则返回 true。
例:
isAllBlank() // trueisAllBlank("", null, " ") // trueisAllBlank("123", " ") // falseisAllBlank("123", "abc") // false注意:该方法与 hasBlank(CharSequence...) 的区别在于:
hasBlank(CharSequence...) 等价于 isBlank(...) || isBlank(...) || ...isBlank(...) && isBlank(...) && ...strs - 字符串列表public static boolean hasEmpty(CharSequence... strs)
是否包含空字符串。
如果指定的字符串数组的长度为 0,或者其中的任意一个元素是空字符串,则返回 true。
例:
StrUtil.hasEmpty() // trueStrUtil.hasEmpty("", null) // trueStrUtil.hasEmpty("123", "") // trueStrUtil.hasEmpty("123", "abc") // falseStrUtil.hasEmpty(" ", "\t", "\n") // false注意:该方法与 isAllEmpty(CharSequence...) 的区别在于:
isEmpty(...) || isEmpty(...) || ...isAllEmpty(CharSequence...) 等价于 isEmpty(...) && isEmpty(...) && ...strs - 字符串列表public static boolean hasEmpty(Iterable<? extends CharSequence> strs)
是否包含空字符串。
如果指定的字符串数组的长度为 0,或者其中的任意一个元素是空字符串,则返回 true。
strs - 字符串列表public static boolean isAllEmpty(CharSequence... strs)
指定字符串数组中的元素,是否全部为空字符串。
如果指定的字符串数组的长度为 0,或者所有元素都是空字符串,则返回 true。
例:
StrUtil.isAllEmpty() // trueStrUtil.isAllEmpty("", null) // trueStrUtil.isAllEmpty("123", "") // falseStrUtil.isAllEmpty("123", "abc") // falseStrUtil.isAllEmpty(" ", "\t", "\n") // false注意:该方法与 hasEmpty(CharSequence...) 的区别在于:
hasEmpty(CharSequence...) 等价于 isEmpty(...) || isEmpty(...) || ...isEmpty(...) && isEmpty(...) && ...strs - 字符串列表public static boolean isAllEmpty(Iterable<? extends CharSequence> strs)
指定字符串数组中的元素,是否全部为空字符串。
如果指定的字符串数组的长度为 0,或者所有元素都是空字符串,则返回 true。
strs - 字符串列表public static boolean isAllNotEmpty(CharSequence... args)
指定字符串数组中的元素,是否都不为空字符串。
如果指定的字符串数组的长度不为 0,或者所有元素都不是空字符串,则返回 true。
例:
StrUtil.isAllNotEmpty() // falseStrUtil.isAllNotEmpty("", null) // falseStrUtil.isAllNotEmpty("123", "") // falseStrUtil.isAllNotEmpty("123", "abc") // trueStrUtil.isAllNotEmpty(" ", "\t", "\n") // true注意:该方法与 isAllEmpty(CharSequence...) 的区别在于:
isAllEmpty(CharSequence...) 等价于 isEmpty(...) && isEmpty(...) && ...!isEmpty(...) && !isEmpty(...) && ...args - 字符串数组public static boolean isNullOrUndefined(CharSequence str)
str - 被检查的字符串public static boolean isEmptyOrUndefined(CharSequence str)
str - 被检查的字符串public static boolean isBlankOrUndefined(CharSequence str)
str - 被检查的字符串public static boolean isAllCharMatch(CharSequence value, Predicate<Character> matcher)
value - 字符串matcher - 匹配器Copyright © 2025. All rights reserved.