Java How to know what has been eliminated HashSet?

How to know what has been eliminated HashSet ?

I have an array int [] x = {2, 4, 4, 5};

When I covert it, HashSet<Integer> set = new HashSet<Integer>(Arrays.asList(x));

How do I know what elements have been eliminated from x into set ?

Jon Skeet
people
quotationmark

Instead of using that constructor, you could use:

Set<Integer> set = new HashSet<>();
for (int value : x) {
    if (!set.add(value)) {
        // Or whatever you want to do
        System.out.println("Detected a duplicate... " + value);
    }
}

people

See more on this question at Stackoverflow