Here you can find the source of getFirst(Collection
public static <T> T getFirst(Collection<T> collection)
//package com.java2s; /******************************************************************************* * Copyright (c) 2005, 2014 //from w w w.j a va2s. co m * * Licensed under the Apache License, Version 2.0 (the "License"); *******************************************************************************/ import java.util.Collection; import java.util.List; public class Main { public static <T> T getFirst(Collection<T> collection) { if (isEmpty(collection)) { return null; } if (collection instanceof List) { return ((List<T>) collection).get(0); } return collection.iterator().next(); } public static boolean isEmpty(Collection<?> collection) { return (collection == null) || collection.isEmpty(); } }