Java tutorial
//package com.java2s; import java.util.Collection; public class Main { /** * * @param <T> * @param collection * @return first element or null if empty */ public static <T> T getFirstElement(Collection<? extends T> collection) { return collection.size() > 0 ? collection.iterator().next() : null; } }