Java tutorial
//package com.java2s; import java.util.Iterator; public class Main { public static <K> Object firstElementOrNull(Iterable iterable) { Iterator iterator = iterable.iterator(); if (iterator.hasNext()) { return iterator.next(); } else { return null; } } }