集册 Java实例教程 检查对象数组的数组是空的还是空的。

检查对象数组的数组是空的还是空的。

欢马劈雪     最近更新时间:2020-01-02 10:19:05

451
检查对象数组的数组是空的还是空的。
/*来自 N o w J a v a . c o m - 时  代  Java*/

//package com.nowjava;


public class Main {


    /**

     * <p>

     * Checks if an array of Object Array is empty or {@code null}.

     * </p>

     * 

     * @param objs

     * @param isContentsCheck

     * @return {@code true} if the Object Array is empty or {@code null}

     */

    public static boolean isEmpty(final Object[] objs,

            Boolean isContentsCheck) {

        if (objs == null || objs.length < 1) {

            return true;

        }

        if (isContentsCheck) {

            for (Object obj : objs) {

                if (isEmpty(obj)) {

                    return true;

                }

            }/* 来自 时代Java公众号 - N o w J a  v a . c o m*/

        }

        return false;

    }


    /**

     * <p>

     * Checks if an array of Object is empty or {@code null}.<br>

     * Each Object element is a String class will call if {@link #isEmptyStr (String)}

     * </p>

     * 

     * @param obj

     * @return {@code true} if the Object is blank or {@code null}

     */

    public static boolean isEmpty(final Object obj) {

        if (obj == null) {

            return true;

        }

        if (obj instanceof String) {

            return isEmptyStr((String) obj);

        }

        return false;

    }


    
展开阅读全文