Java tutorial
//package com.java2s; //License from project: Apache License import java.util.*; public class Main { public static boolean hasUniqueObject(Collection collection) { if (isEmpty(collection)) { return false; } else { boolean hasCandidate = false; Object candidate = null; Iterator i$ = collection.iterator(); while (i$.hasNext()) { Object elem = i$.next(); if (!hasCandidate) { hasCandidate = true; candidate = elem; } else if (candidate != elem) { return false; } } return true; } } public static boolean isEmpty(Collection collection) { return collection == null || collection.isEmpty(); } public static boolean isEmpty(Map map) { return map == null || map.isEmpty(); } }