Java tutorial
//package com.java2s; import java.util.*; public class Main { public static Object findSingleObject(Collection c) { if (c == null || c.isEmpty()) return null; if (c.size() > 1) throw new IllegalStateException("found more than one object when single object requested"); return c.iterator().next(); } }