From 2630befe2daed1c54739a07c15a7afdaa6909135 Mon Sep 17 00:00:00 2001 From: ray bi Date: Tue, 16 Aug 2022 13:23:43 +0800 Subject: [PATCH] check whether the string has letter character --- .../java/cn/hutool/core/util/StrUtil.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) 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 e0d6dc119..9f4bfc667 100755 --- a/hutool-core/src/main/java/cn/hutool/core/util/StrUtil.java +++ b/hutool-core/src/main/java/cn/hutool/core/util/StrUtil.java @@ -468,4 +468,24 @@ public class StrUtil extends CharSequenceUtil implements StrPool { public static String format(CharSequence template, Map map, boolean ignoreNull) { return StrFormatter.format(template, map, ignoreNull); } + + /** + *

指定字符串数组中,是否包含空字符串。

+ *

如果传入参数对象不是为空,则返回false。如果传入的参数不是String则返回false 如果字符串包含字母,不区分大小写,则返回true

+ * @param obj 对象 + * @return 如果为字符串,是否有字母 + */ + public static boolean hasLetter(Object obj) { + if (null == obj) { + return false; + } else if (obj instanceof String) { + char[] chars = ((String) obj).toCharArray(); + for (char c : chars){ + if (CharUtil.isLetter(c)){ + return true; + } + } + } + return false; + } }