Here you can find the source of single(List
public static <T> T single(List<T> list)
//package com.java2s; //License from project: Open Source License import java.util.List; public class Main { public static <T> T single(List<T> list) { if (list.size() == 1) { return list.get(0); } else if (list.size() == 0) { throw new RuntimeException("No results found!"); } else {/*from www. j a v a 2 s.c o m*/ throw new RuntimeException("More results returned than one!"); } } }