title: How to use Sets as keys in Java Maps
body: <p>I have a Map that uses a Set for the key type, like this:</p>
  
  <pre><code>Map&lt;Set&lt;Thing&gt;, Val&gt; map;
  </code></pre>
  
  <p>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.</p>
  
  <pre><code>System.out.println(map.containsKey(myBunchOfThings)); // false.
  for (Set&lt;Thing&gt; k : map.keySet()) {
    if (k.hashCode() == myBunchOfThings.hashCode() &amp;&amp; k.equals(myBunchOfThings) {
       System.out.println("Fail at life."); // it prints this.
    }
  }
  </code></pre>
  
  <p>Do I just fundamentally misunderstand the contract for containsKey? Is there a secret to using sets (or more generally, collections) as keys to maps?</p>