Here you can find the source of first(Collection
public static <T> T first(Collection<T> collection)
//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; } }