Here you can find the source of first(Collection extends E> collection, E alternative)
public static <E> E first(Collection<? extends E> collection, E alternative)
//package com.java2s; //License from project: Apache License import java.util.Collection; import java.util.Iterator; public class Main { public static <E> E first(Collection<? extends E> collection, E alternative) { Iterator<? extends E> iterator = collection.iterator(); if (iterator.hasNext()) { return iterator.next(); }/*from www . j a v a 2s.co m*/ return alternative; } }