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.*; public class Main { public static <T> T getFirst(Collection<T> collection) { if (isEmpty(collection)) { return null; }//from w w w . j a v a 2 s. c o m return collection.iterator().next(); } public static boolean isEmpty(Collection collection) { return ((collection == null) || collection.isEmpty()); } }