Java Collection Search hasElements(Collection collection)

Here you can find the source of hasElements(Collection collection)

Description

Checks whether the COLLECTION is not NULL and has at least one element.

License

Apache License

Parameter

Parameter Description
T the generic type
collection the collection

Return

true, if successful

Declaration

public static <T> boolean hasElements(Collection<T> collection) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.Collection;

import java.util.Map;

public class Main {
    /**//ww  w  .ja va2  s. com
     * Checks whether the COLLECTION is not NULL and has at least one element.
     * 
     * @param <T>
     *            the generic type
     * @param collection
     *            the collection
     * @return true, if successful
     */
    public static <T> boolean hasElements(Collection<T> collection) {
        return (null != collection && collection.size() > 0);
    }

    /**
     * Checks whether the MAP is not NULL and has at least one element.
     * 
     * @param <T>
     *            the generic type
     * @param <V>
     *            the value type
     * @param map
     *            the map
     * @return true, if successful
     */
    public static <T, V> boolean hasElements(Map<T, V> map) {
        return (null != map && map.size() > 0);
    }
}

Related

  1. getSingleElement(Collection collection)
  2. getSingleItem(Collection values)
  3. getSingleValue(Iterable collection)
  4. hasElements(Collection c)
  5. hasElements(Collection c)
  6. hasElements(Collection t)
  7. hashCapacityFor(Collection collection)
  8. hasLength(final Collection collection)
  9. hasNoValue(Collection collection)