How to use Sets as keys in Java Maps
问题 I have a Map that uses a Set for the key type, like this: Map<Set<Thing>, Val> map; When I query map.containsKey(myBunchOfThings), it returns false, and I don't understand why. I can iterate through each key in the keyset and verify there is a key that (1) has the same hashCode, and (2) is equals() to myBunchOfThings. System.out.println(map.containsKey(myBunchOfThings)); // false. for (Set<Thing> k : map.keySet()) { if (k.hashCode() == myBunchOfThings.hashCode() && k.equals(myBunchOfThings) {