Here you can find the source of getFirst(Iterable
public static <T> T getFirst(Iterable<T> iterable)
//package com.java2s; //it under the terms of the GNU Affero General Public License as published by import java.util.Iterator; public class Main { /**//from w w w . j a v a 2 s . c o m * @deprecated Strongly consider if you want the first element or rather only expect * one element. In the latter case, use {@link #getUnique(Iterable)} or * {@link #getSingleIfExist(Iterable)}. */ public static <T> T getFirst(Iterable<T> iterable) { return getFirst(iterable, null); } public static <T> T getFirst(Iterable<? extends T> iterable, T def) { final Iterator<? extends T> iter = iterable.iterator(); return iter.hasNext() ? iter.next() : def; } }