title: Internal implementation of java.util.HashMap and HashSet
body: <p>I have been trying to understand the internal implementation of <code>java.util.HashMap</code> and <code>java.util.HashSet</code>.</p>
  
  <p>Following are the doubts popping in my mind for a while:</p>
  
  <ol>
  <li>Whats is the importance of the <code>@Override public int hashcode()</code> in a HashMap/HashSet? Where is this hash code used internally?</li>
  <li>I have generally seen the key of the HashMap be a <code>String</code> like <code>myMap&lt;String,Object&gt;</code>. Can I map the values against <code>someObject</code> (instead of String) like <code>myMap&lt;someObject, Object&gt;</code>? What all contracts do I need to obey for this happen successfully?</li>
  </ol>
  
  <p>Thanks in advance !</p>
  
  <p><strong>EDIT:</strong></p>
  
  <ol>
  <li>Are we saying that the hash code of the key (check!) is the actual thing against which the value is mapped in the hash table? And when we do <code>myMap.get(someKey);</code> java is internally calling <code>someKey.hashCode()</code> to get the number in the Hash table to be looked for the resulting value?</li>
  </ol>
  
  <p><strong>Answer:</strong> Yes.</p>
  
  <p><strong>EDIT 2:</strong></p>
  
  <ol start="2">
  <li>In a <code>java.util.HashSet</code>, from where is the key generated for the Hash table? Is it from the object that we are adding eg. <code>mySet.add(myObject);</code> then <code>myObject.hashCode()</code> is going to  decide where this is placed in the hash table? (as we don't give keys in a HashSet).</li>
  </ol>
  
  <p><strong>Answer:</strong> The object added becomes the key. The value is dummy!</p>