Here you can find the source of firstElement(Collection
public static <T> T firstElement(Collection<T> c)
//package com.java2s; //License from project: Apache License import java.util.Collection; public class Main { public static <T> T firstElement(Collection<T> c) { if (c != null && !c.isEmpty()) { return c.iterator().next(); }//from ww w . j a v a 2 s . co m return null; } }