Checks if an array of Object Array is empty or null . - Java Collection Framework

Java examples for Collection Framework:Array Element

Description

Checks if an array of Object Array is empty or null .

Demo Code


//package com.java2s;

public class Main {

    /**//from w ww  .  java2  s .  com
     * <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;
                }
            }
        }
        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;
    }

    /**
     * <p>
     * Checks if an array of String is empty or {@code null}.
     * </p>
     * 
     * @deprecated
     * @param str
     * @return {@code true} if the String is empty or {@code null}
     */
    @Deprecated
    private static boolean isEmptyStr(final String str) {
        return str == null || str.length() < 1;
    }
}

Related Tutorials