Here you can find the source of uniqueResult(final Collection
public static <T> T uniqueResult(final Collection<T> c)
//package com.java2s; //License from project: BSD License import java.util.Collection; public class Main { public static <T> T uniqueResult(final Collection<T> c) { switch (c.size()) { case 0:/* ww w . ja v a 2s. co m*/ return null; case 1: return c.iterator().next(); default: throw new IllegalStateException("Unexpected number of elements in collection: " + c.size()); } } }