Java Array Empty Check isEmpty(T[] array)

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

Description

Indicates whether an array are null or consist of null

License

Apache License

Parameter

Parameter Description
array An array

Return

True if the array input is null, or consist of null. False if one of its item is not null

Declaration

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

Method Source Code

//package com.java2s;
/***********************************************************************************************************************
 * //from www .  j av  a2 s. co m
 * Copyright (C) 2013, 2014 by huanju (http://www.yy.com)
 * http://www.yy.com/
 *
 ***********************************************************************************************************************
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations under the License.
 *
 **********************************************************************************************************************/

import java.util.Collection;
import java.util.Map;

public class Main {
    /**
     * Indicates whether a collection is null or consist of null
     * 
     * @param cols
     *            A collection
     * @return True if the collection input is null, or consist of null. False if one of its item is not null
     */
    public static boolean isEmpty(Collection<?> cols) {
        if (cols == null || cols.isEmpty())
            return true;
        for (Object o : cols) {
            if (o != null)
                return false;
        }
        return true;
    }

    /**
     * Indicates whether a collection is null or consist of null
     * 
     * @param cols
     *            A collection
     * @return True if the collection input is null, or consist of null. False if one of its item is not null
     */
    public static boolean isEmpty(Map<?, ?> cols) {
        return cols == null || cols.isEmpty();
    }

    /**
     * Indicates whether an array are null or consist of null
     * 
     * @param array
     *            An array
     * @return True if the array input is null, or consist of null. False if one of its item is not null
     */
    public static <T> boolean isEmpty(T[] array) {
        if (array == null || array.length == 0)
            return true;
        for (Object o : array) {
            if (o != null)
                return false;
        }
        return true;
    }
}

Related

  1. isEmpty(T[] array)
  2. isEmpty(T[] array)
  3. isEmpty(T[] array)
  4. isEmpty(T[] array)
  5. isEmpty(T[] array)
  6. isEmptyOrNull(Object[] array)
  7. isEmptyOrNull(Object[] array)
  8. isNonEmpty(Object[] array)
  9. isNotEmpty(boolean[] values)