Here you can find the source of single(Iterator
public static <T> T single(Iterator<T> i)
//package com.java2s; //License from project: Apache License import java.util.Iterator; public class Main { /**//from ww w . j ava 2 s. c om * A single item or null * * @param iterable The iterable * @param <T> The item * @return A single item or null */ public static <T> T single(Iterable<T> iterable) { Iterator<T> i = iterable.iterator(); return single(i); } public static <T> T single(Iterator<T> i) { if (i.hasNext()) { return i.next(); } return null; } }