Java tutorial
//package com.java2s; import java.util.Collection; import java.util.Iterator; public class Main { public static <E> E getFirst(Collection<E> collection, E defaultValue) { Iterator<E> iterator = collection.iterator(); return iterator.hasNext() ? iterator.next() : defaultValue; } public static <E> E getFirst(Collection<E> collection) { return getFirst(collection, null); } }