title: What happens when a duplicate key is put into a HashMap?
body: <p>If I pass the same key multiple times to <code>HashMap</code>’s <code>put</code> method, what happens to the original value? And what if even the value repeats? I didn’t find any documentation on this.</p>
  
  <p>Case 1: Overwritten values for a key</p>
  
  <pre><code>Map mymap = new HashMap();
  mymap.put("1","one");
  mymap.put("1","not one");
  mymap.put("1","surely not one");
  System.out.println(mymap.get("1"));
  </code></pre>
  
  <p>We get <code>surely not one</code>.</p>
  
  <p>Case 2: Duplicate value</p>
  
  <pre><code>Map mymap = new HashMap();
  mymap.put("1","one");
  mymap.put("1","not one");
  mymap.put("1","surely not one");
  // The following line was added:
  mymap.put("1","one");
  System.out.println(mymap.get("1"));
  </code></pre>
  
  <p>We get <code>one</code>.</p>
  
  <p>But what happens to the other values? I was teaching basics to a student and I was asked this. Is the <code>Map</code> like a bucket where the last value is referenced (but in memory)?</p>