Java Array Empty Check isEmpty(T[] array)

Here you can find the source of isEmpty(T[] array)

Description

Returns if the given array is null or empty.

License

Open Source License

Parameter

Parameter Description
array The array to test.

Return

true if the given array is null or empty .

Declaration

public static <T extends Object> boolean isEmpty(T[] array) 

Method Source Code

//package com.java2s;
/*/*from  w w w.java 2 s  .c o  m*/
 * #%L
 * Sigmah
 * %%
 * Copyright (C) 2010 - 2016 URD
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public
 * License along with this program.  If not, see
 * <http://www.gnu.org/licenses/gpl-3.0.html>.
 * #L%
 */

import java.util.Collection;

import java.util.Map;

public class Main {
    /**
     * Returns if the given {@code collection} is {@code null} or empty.
     * 
     * @param collection
     *          The collection to test.
     * @return {@code true} if the given {@code collection} is {@code null} or {@code empty}.
     */
    public static <C extends Collection<?>> boolean isEmpty(C collection) {
        return collection == null || collection.isEmpty();
    }

    /**
     * Returns if the given {@code array} is {@code null} or empty.
     * 
     * @param array
     *          The array to test.
     * @return {@code true} if the given {@code array} is {@code null} or {@code empty}.
     */
    public static <T extends Object> boolean isEmpty(T[] array) {
        return array == null || array.length == 0;
    }

    /**
     * Returns if the given {@code map} is {@code null} or empty.
     * 
     * @param map
     *          The map to test.
     * @return {@code true} if the given {@code map} is {@code null} or {@code empty}.
     */
    public static <M extends Map<?, ?>> boolean isEmpty(M map) {
        return map == null || map.isEmpty();
    }
}

Related

  1. isEmpty(T[] arr)
  2. isEmpty(T[] arr)
  3. isEmpty(T[] array)
  4. isEmpty(T[] array)
  5. isEmpty(T[] array)
  6. isEmpty(T[] array)
  7. isEmpty(T[] array)
  8. isEmptyOrNull(Object[] array)
  9. isEmptyOrNull(Object[] array)