Java Collection Empty isEmpty(final Collection collection)

Here you can find the source of isEmpty(final Collection collection)

Description

Returns true if the given collection is null or empty.

License

Open Source License

Parameter

Parameter Description
collection The collection to determine if it is null or empty.

Return

True if the given collection is null or empty.

Declaration

public static boolean isEmpty(final Collection<?> collection) 

Method Source Code

//package com.java2s;
/*//from  w w  w  . jav a 2  s. co m
 * File:                CollectionUtil.java
 * Authors:             Justin Basilico
 * Company:             Sandia National Laboratories
 * Project:             Cognitive Foundry
 *
 * Copyright March 25, 2008, Sandia Corporation.
 * Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive
 * license for use of this work by or on behalf of the U.S. Government. Export
 * of this program may require a license from the United States Government.
 * See CopyrightHistory.txt for complete details.
 *
 */

import java.util.Collection;

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

    /**
     * Returns true if the given iterable is null or empty.
     *
     * @param iterable The iterable to determine if it is null or empty.
     * @return True if the given iterable is null or empty.
     */
    public static boolean isEmpty(final Iterable<?> iterable) {
        if (iterable == null) {
            // It is null, so it is empty.
            return true;
        } else if (iterable instanceof Collection) {
            return ((Collection<?>) iterable).isEmpty();
        } else {
            return !iterable.iterator().hasNext();
        }
    }
}

Related

  1. isEmpty(Collection collection, String messgae)
  2. isEmpty(Collection items)
  3. isEmpty(Collection c)
  4. isEmpty(final Collection values)
  5. isEmpty(final Collection coll)
  6. isEmpty(final Collection collection)
  7. isEmpty(final Collection collection)
  8. isEmpty(final Collection collection)
  9. isEmpty(final Collection value)