diff --git a/hutool-core/src/main/java/cn/hutool/core/util/StrUtil.java b/hutool-core/src/main/java/cn/hutool/core/util/StrUtil.java
index eff4b7e3c..511db0223 100644
--- a/hutool-core/src/main/java/cn/hutool/core/util/StrUtil.java
+++ b/hutool-core/src/main/java/cn/hutool/core/util/StrUtil.java
@@ -461,21 +461,53 @@ public class StrUtil {
// ------------------------------------------------------------------------ Empty
/**
- * 字符串是否为空,空的定义如下:
- * 1、为null
- * 2、为""
+ *
字符串是否为空,空的定义如下:
+ *
+ * - {@code null}
+ * - 空字符串:{@code ""}
+ *
+ *
+ * 例:
+ *
+ * - {@code StrUtil.isEmpty(null) // true}
+ * - {@code StrUtil.isEmpty("") // true}
+ * - {@code StrUtil.isEmpty(" \t\n") // false}
+ * - {@code StrUtil.isEmpty("abc") // false}
+ *
+ *
+ * 注意:该方法与 {@link #isBlank(CharSequence)} 的区别是:该方法不校验空白字符。
+ * 建议:
+ *
+ * - 该方法建议用于工具类或任何可以预期的方法参数的校验中。
+ * - 需要同时校验多个字符串时,建议采用 {@link #hasEmpty(CharSequence...)} 或 {@link #isAllEmpty(CharSequence...)}
+ *
*
* @param str 被检测的字符串
* @return 是否为空
+ *
+ * @see #isBlank(CharSequence)
+ * @since 1.0.0
*/
public static boolean isEmpty(CharSequence str) {
return str == null || str.length() == 0;
}
/**
- * 如果对象是字符串是否为空串空的定义如下:
- * 1、为null
- * 2、为""
+ * 如果对象是字符串是否为空串,空的定义如下:
+ *
+ * - {@code null}
+ * - 空字符串:{@code ""}
+ *
+ *
+ * 例:
+ *
+ * - {@code StrUtil.isEmptyIfStr(null) // true}
+ * - {@code StrUtil.isEmptyIfStr("") // true}
+ * - {@code StrUtil.isEmptyIfStr(" \t\n") // false}
+ * - {@code StrUtil.isEmptyIfStr("abc") // false}
+ *
+ *
+ * 注意:该方法与 {@link #isBlankIfStr(Object)} 的区别是:该方法不校验空白字符。
*
* @param obj 对象
* @return 如果为字符串是否为空串
@@ -491,12 +523,27 @@ public class StrUtil {
}
/**
- * 字符串是否为非空白,非空白的定义如下:
- * 1、不为null
- * 2、不为""
+ * 字符串是否为非空白,非空白的定义如下:
+ *
+ * - 不为 {@code null}
+ * - 不为空字符串:{@code ""}
+ *
+ *
+ * 例:
+ *
+ * - {@code StrUtil.isNotEmpty(null) // false}
+ * - {@code StrUtil.isNotEmpty("") // false}
+ * - {@code StrUtil.isNotEmpty(" \t\n") // true}
+ * - {@code StrUtil.isNotEmpty("abc") // true}
+ *
+ *
+ * 注意:该方法与 {@link #isNotBlank(CharSequence)} 的区别是:该方法不校验空白字符。
+ * 建议:该方法建议用于工具类或任何可以预期的方法参数的校验中。
*
* @param str 被检测的字符串
* @return 是否为非空
+ *
+ * @see StrUtil#isEmpty(CharSequence)
*/
public static boolean isNotEmpty(CharSequence str) {
return false == isEmpty(str);
@@ -507,6 +554,7 @@ public class StrUtil {
*
* @param str 被检查的字符串
* @return 原字符串或者空串
+ *
* @see #nullToEmpty(CharSequence)
* @since 4.6.3
*/
@@ -525,7 +573,7 @@ public class StrUtil {
}
/**
- * 如果字符串是null
,则返回指定默认字符串,否则返回字符串本身。
+ * 如果字符串是 null
,则返回指定默认字符串,否则返回字符串本身。
*
*
* nullToDefault(null, "default") = "default"
@@ -591,7 +639,24 @@ public class StrUtil {
}
/**
- * 是否包含空字符串
+ * 是否包含空字符串。
+ * 如果指定的字符串数组的长度为 0,或者其中的任意一个元素是空字符串,则返回 true。
+ *
+ *
+ * 例:
+ *
+ * - {@code StrUtil.hasEmpty() // true}
+ * - {@code StrUtil.hasEmpty("", null) // true}
+ * - {@code StrUtil.hasEmpty("123", "") // true}
+ * - {@code StrUtil.hasEmpty("123", "abc") // false}
+ * - {@code StrUtil.hasEmpty(" ", "\t", "\n") // false}
+ *
+ *
+ * 注意:该方法与 {@link #isAllEmpty(CharSequence...)} 的区别在于:
+ *
+ * hasEmpty(CharSequence...) 等价于 {@code isEmpty(...) || isEmpty(...) || ...}
+ * {@link #isAllEmpty(CharSequence...)} 等价于 {@code isEmpty(...) && isEmpty(...) && ...}
+ *
*
* @param strs 字符串列表
* @return 是否包含空字符串
@@ -610,10 +675,27 @@ public class StrUtil {
}
/**
- * 是否全部为空字符串
+ * 指定字符串数组中的元素,是否全部为空字符串。
+ * 如果指定的字符串数组的长度为 0,或者所有元素都是空字符串,则返回 true。
+ *
+ *
+ * 例:
+ *
+ * - {@code StrUtil.isAllEmpty() // true}
+ * - {@code StrUtil.isAllEmpty("", null) // true}
+ * - {@code StrUtil.isAllEmpty("123", "") // false}
+ * - {@code StrUtil.isAllEmpty("123", "abc") // false}
+ * - {@code StrUtil.isAllEmpty(" ", "\t", "\n") // false}
+ *
+ *
+ * 注意:该方法与 {@link #hasEmpty(CharSequence...)} 的区别在于:
+ *
+ * {@link #hasEmpty(CharSequence...)} 等价于 {@code isEmpty(...) || isEmpty(...) || ...}
+ * isAllEmpty(CharSequence...) 等价于 {@code isEmpty(...) && isEmpty(...) && ...}
+ *
*
* @param strs 字符串列表
- * @return 是否全部为空字符串
+ * @return 所有字符串是否为空白
*/
public static boolean isAllEmpty(CharSequence... strs) {
if (ArrayUtil.isEmpty(strs)) {
@@ -629,10 +711,27 @@ public class StrUtil {
}
/**
- * 是否存都不为{@code null}或空对象,通过{@link StrUtil#hasEmpty(CharSequence...)} 判断元素
+ * 指定字符串数组中的元素,是否都不为空字符串。
+ * 如果指定的字符串数组的长度不为 0,或者所有元素都不是空字符串,则返回 true。
+ *
*
- * @param args 被检查的对象,一个或者多个
- * @return 是否都不为空
+ * 例:
+ *
+ * - {@code StrUtil.isAllNotEmpty() // false}
+ * - {@code StrUtil.isAllNotEmpty("", null) // false}
+ * - {@code StrUtil.isAllNotEmpty("123", "") // false}
+ * - {@code StrUtil.isAllNotEmpty("123", "abc") // true}
+ * - {@code StrUtil.isAllNotEmpty(" ", "\t", "\n") // true}
+ *
+ *
+ * 注意:该方法与 {@link #isAllEmpty(CharSequence...)} 的区别在于:
+ *
+ * {@link #isAllEmpty(CharSequence...)} 等价于 {@code isEmpty(...) && isEmpty(...) && ...}
+ * isAllNotEmpty(CharSequence...) 等价于 {@code !isEmpty(...) && !isEmpty(...) && ...}
+ *
+ *
+ * @param args 字符串数组
+ * @return 所有字符串是否都不为为空白
* @since 5.3.6
*/
public static boolean isAllNotEmpty(CharSequence... args) {