Here you can find the source of toSingleton(Collection
public static <T> T toSingleton(Collection<T> l)
//package com.java2s; //License from project: Open Source License import java.util.Collection; import java.util.Iterator; public class Main { public static <T> T toSingleton(Collection<T> l) { return toSingleton(l.iterator()); }/*from www . j av a2s . com*/ public static <T> T toSingleton(Iterator<T> it) { if (!it.hasNext()) return null; return it.next(); } public static <T> T toSingleton(T[] l) { if (l.length == 0) return null; return l[0]; } }