I created a HashSet of Integers (Ex. 5). When I try to check the HashSet for the same added element but in a Double element version (Ex. 5d, 5.0). It couldn't identify and returns false!
My assumption was, Java would implicitly convert Double to Integer and try to identify. But it didn't! Why is this the case?
Set<Integer> set = new HashSet<Integer>();
set.add(5);
System.out.println(set.contains(5d)); // returns false? Why?
System.out.println(set.contains(5.0));// returns false? Why?
System.out.println(set.contains(5)); // returns true
System.out.println(5 == 5d); // returns true