Here you can find the source of singleOrDefault(Iterator
public static <T> T singleOrDefault(Iterator<T> iterator)
//package com.java2s; //License from project: BSD License import java.util.Iterator; public class Main { public static <T> T singleOrDefault(Iterator<T> iterator) { if (!iterator.hasNext()) { return null; }//from www. j a v a2 s. c o m T first = iterator.next(); if (iterator.hasNext()) { throw new IllegalStateException("Expected single result, but got more than one"); } return first; } }