// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.util.HashSet;
import java.util.Set;

public class TestDuplicates {
    public static boolean containsDuplicate(int[] nums) {
        Set<Integer> numset = new HashSet<Integer>();
        for(int num : nums) {
            if(!numset.add(num)) {
                return true;
            }
        }
        return false;
    }
    public static void main(String[] args) {
        System.out.println(containsDuplicate(new int [] { 1, 2, 3, 1 }));
        System.out.println(containsDuplicate(new int [] { 1, 2, 3, 4 }));
        System.out.println(containsDuplicate(new int [] { 1, 1, 1, 3, 4, 4, 3, 2, 4, 2 }));
    }
}
