From eda9a11aa05fdd3bab911d815f0edc6cf4765e4f Mon Sep 17 00:00:00 2001 From: p2x9nfpei <2196435763@qq.com> Date: Mon, 28 Apr 2025 23:59:03 +0800 Subject: [PATCH] ADD file via upload --- StringUtil.java | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 StringUtil.java diff --git a/StringUtil.java b/StringUtil.java new file mode 100644 index 0000000..158efb9 --- /dev/null +++ b/StringUtil.java @@ -0,0 +1,31 @@ +package com.utils; + +// 字符串工具类,提供字符串判空相关方法 +public class StringUtil { + + // 判断字符串是否为空 + // 空值条件:null、空字符串或"null"字符串 + public static boolean isEmpty(String s) { + // 检查字符串是否为null + if (s == null) { + return true; + } + // 检查字符串是否为空字符串 + if (s.equals("")) { + return true; + } + // 检查字符串是否为"null"字符串 + if (s.equals("null")) { + return true; + } + // 不满足以上条件则返回false + return false; + } + + // 判断字符串是否非空 + // 直接调用isEmpty方法取反 + public static boolean isNotEmpty(String s) { + // 返回isEmpty方法的相反结果 + return !StringUtil.isEmpty(s); + } +} \ No newline at end of file