Java Collection First first(Collection collection)

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

Description

Replaces first() LINQ Returns first object of collection or null if empty

License

Apache License

Declaration

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

Method Source Code

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

import java.util.Collection;

import java.util.Iterator;

public class Main {
    /**/*from   w ww  .  java  2 s  .c  om*/
     * Replaces first() LINQ
     *
     * Returns first object of collection or null if empty
     */
    public static <T> T first(Collection<T> collection) {
        Iterator<T> iterator = collection.iterator();
        if (iterator.hasNext())
            return iterator.next();
        else
            return null;
    }
}

Related

  1. first(Collection values)
  2. first(Collection collection)
  3. first(Collection self)
  4. first(Collection c)
  5. first(Collection c)
  6. first(Collection collection)
  7. firstElement(Collection in)
  8. firstElement(Collection c)
  9. firstElementOf(final Collection collection)