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.Map; public class Main { public static <T> T getFirst(Collection<T> collection) { if (isEmpty(collection)) { return null; }// ww w . j a v a2 s .c o m return collection.iterator().next(); } @SuppressWarnings("rawtypes") public static boolean isEmpty(Collection collection) { return (collection == null) || collection.isEmpty(); } @SuppressWarnings("rawtypes") public static boolean isEmpty(Map map) { return (map == null) || map.isEmpty(); } }