Here you can find the source of isEmpty(final Collection> collection)
Parameter | Description |
---|---|
collection | The collection to determine if it is null or empty. |
public static boolean isEmpty(final Collection<?> collection)
//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(); } } }