Here you can find the source of getFirstItem(Collection
public static <X> X getFirstItem(Collection<X> c)
//package com.java2s; import java.util.*; public class Main { /**/*w ww.ja va 2 s . co m*/ * Returns the first item in the collection or null if the collection is empty */ public static <X> X getFirstItem(Collection<X> c) { X o; if (c == null || c.isEmpty()) { o = null; } else if (c instanceof List) { o = ((List<X>) c).get(0); } else { o = c.iterator().next(); } return o; } }