Java tutorial
//package com.java2s; //License from project: Open Source License import java.util.Collection; import java.util.HashSet; import java.util.Set; public class Main { /** * Returns true if every element in a collection are unique by {@link Object#equals(Object)}. */ public static boolean elementsAreUnique(Collection<?> items) { final Set<Object> testSet = new HashSet<>(); for (Object item : items) { final boolean itemAlreadyExists = !testSet.add(item); // see Set documentation if (itemAlreadyExists) { return false; } } return true; } }