/** * 方法描述:自定义判断是否为空 * 创建作者:李兴武 * 创建日期:2017-06-22 19:50:01 * * @param str the str * @return the boolean */ public static Boolean isBlank(String str) { if (str != null) str = str.replaceAll("\r\n|\n\r|\n|\r|\f|\t", ""); if (str == null) return true; else if (str.equals("")) return true; else if (str.equals("null")) return true; else if (str.equals("NULL")) return true; else if (str.equals("(null)")) return true; else if (str.equals("(NULL)")) return true; else if (str.trim().length() == 0) return true; return false; } /** * 方法描述:判断obj是否为空 * 创建作者:李兴武 * 创建日期:2017-06-22 19:50:01 * * @param obj the 判断的对象 * @return the boolean */ public static Boolean isBlank(Object obj) { if (obj != null) { return isBlank(String.valueOf(obj)); } return true; }
以下字符全部返回true
1. \r\n|\n\r|\n|\r|\f|\t
2. null
3. “”
4. “null”
5. “NULL”
6. “(null)”
7. “(NULL)”
本文介绍了一种自定义的方法来判断字符串或对象是否为空,包括处理多种特殊空值情况,如空字符串、null关键字的不同形式等。
1362

被折叠的 条评论
为什么被折叠?



