title: Why do Set data structures in Java use Map internally?
body: <p>I am wondering why do <a href="http://www.docjar.com/html/api/java/util/HashSet.java.html" rel="noreferrer">HashSet</a> uses <code>HashMap</code>, <code>TreeSet</code> uses <code>TreeMap</code>, and <code>LinkedHashSet</code> uses <code>LinkedHashMap</code> internally behind the scene ? since <code>Set</code> is only carrying and storing the key but the value, so isn't using extra memory space like being not economical ? </p>
  
  <p>The <code>Entry</code> inner class that <code>HashMap</code> has is the following</p>
  
  <pre><code>class Entry&lt;K,V&gt; implements Map.Entry&lt;K,V&gt; {
      final K key;
      V value;
      Entry&lt;K,V&gt; next;
      final int hash;
      ...
      ....
  }
  </code></pre>
  
  <p>For Set we don't really need that <code>V value</code> variable, correct ? So what's the benefit and main reason of using a map object internally ? </p>