Clarification regarding collision handling in Java for my contact based app
<p>I am using java.util.HashMap for association between a contact Name and a list of phone numbers associated with the contact so it is of type <code>String, List&lt;String&gt;</code>. However there can be more than one keys that can map to the the same bucket correct as in Say key1:&lt;1234,5678> is stored in index 2 in the hash Map. I could have another key2 that can hash into the same index. So, will the key1:&lt;1234,5678> be replaced by key2:&lt;7890,1456> ???? Or will it be chained and both key1 and key2 will be stored in that index ?</p>

<p>EDIT:
I'm trying to understand this, the code below only returns New Mexico. Now in this case both they both get the same hashcode so this is a collision correct ? In that case shouldn't both the values be chained ? So shouldn't the storage look like say hashcode is 2 then at the index of 2 in the map (OR array) it should be 1-Mexico, 1-New mexico correct? So the values returned should be of Mexico and New mexico ? Why isn't it getting chained here ? </p>

<pre><code>public static void main(String[] args)
    {
        Map&lt;Integer,String&gt; map = new HashMap&lt;Integer,String&gt;();
        map.put(1, "Mexico");
        map.put(1, "New Mexico");
        System.out.println(map.get(1));

    }
</code></pre>
