Here you can find the source of getFirst(Collection
public static <T> T getFirst(Collection<T> collection)
//package com.java2s; //License from project: Apache License import java.util.Collection; import java.util.Iterator; public class Main { public static <T> T getFirst(Collection<T> collection) { if (collection != null) { Iterator<T> iterator = collection.iterator(); return iterator.hasNext() ? iterator.next() : null; }/*from w w w.j a v a2 s .c o m*/ return null; } }