Here you can find the source of getFirstOrNull(Iterable
public static <T> T getFirstOrNull(Iterable<T> it)
//package com.java2s; //License from project: Open Source License import java.util.Iterator; import java.util.NoSuchElementException; public class Main { public static <T> T getFirstOrNull(Iterable<T> it) { if (it == null) return null; Iterator<T> i = it.iterator(); if (i == null || !i.hasNext()) return null; try {/*w w w. java 2 s . co m*/ return i.next(); } catch (NoSuchElementException e) { return null; } } }