java 判斷數據是否為空


  /**
     * 方法描述:自定義判斷是否為空
     * 創建作者:李興武
     * 創建日期: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)”


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM