Here you can find the source of getUnique(Iterable
public static <T> T getUnique(Iterable<T> iterable)
//package com.java2s; //it under the terms of the GNU Affero General Public License as published by import java.util.Iterator; public class Main { public static <T> T getUnique(Iterable<T> iterable) { final Iterator<? extends T> iter = iterable.iterator(); if (!iter.hasNext()) { throw new IllegalArgumentException("No element in " + iterable); }/* w w w .ja v a 2 s. com*/ final T result = iter.next(); if (iter.hasNext()) { throw new IllegalArgumentException("More than (expected) one element in " + iterable); } return result; } }