Here you can find the source of getFirst(Collection
public static <T> T getFirst(Collection<T> set)
//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> set) { if (isNotEmpty(set)) { for (T item : set) { if (item != null) { return item; }//from www.java 2 s. c om } } return null; } public static boolean isNotEmpty(Collection<? extends Object> col) { return col != null && col.size() > 0; } public static boolean isNotEmpty(Map<? extends Object, ? extends Object> map) { return map != null && map.size() > 0; } }