Java Collection First getFirst(Collection collection)

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

Description

get First

License

Open Source License

Declaration

public static <T> T getFirst(Collection<T> collection) 

Method Source Code

//package com.java2s;
/*/*from   www .j  a v a 2  s.  c o  m*/
 * Copyright 2009-2012 Evun Technology. 
 * 
 * This software is the confidential and proprietary information of
 * Evun Technology. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with evun.cn.
 */

import java.util.Collection;

import java.util.Map;

public class Main {

    public static <T> T getFirst(Collection<T> collection) {
        if (isEmpty(collection)) {
            return null;
        }

        return collection.iterator().next();
    }

    public static boolean isEmpty(Collection collection) {
        return (collection == null || collection.isEmpty());
    }

    /**
     * Return <code>true</code> if the supplied Map is <code>null</code> or
     * empty. Otherwise, return <code>false</code>.
     * 
     * @param map
     *            the Map to check
     * @return whether the given Map is empty
     */
    public static boolean isEmpty(Map map) {
        return (map == null || map.isEmpty());
    }

    public static boolean isEmpty(Object[] array) {
        return array == null || array.length == 0;
    }

    public static boolean isEmpty(int[] array) {
        return array == null || array.length == 0;
    }

    /**
     * <p>
     * Checks if an array of primitive bytes is empty or {@code null}.
     * </p>
     *
     * @param array
     *            the array to test
     * @return {@code true} if the array is empty or {@code null}
     * @since 2.1
     */
    public static boolean isEmpty(byte[] array) {
        return array == null || array.length == 0;
    }
}

Related

  1. getFirst(Collection collection)
  2. getFirst(Collection bag)
  3. getFirst(Collection c)
  4. getFirst(Collection col)
  5. getFirst(Collection coll)
  6. getFirst(Collection collection)
  7. getFirst(Collection collection)
  8. getFirst(Collection collection)
  9. getFirst(Collection collection)