title: HashMap.put() is overriding existing item for different key
body: <p>I have a HashMap which I am using to store objects of type <strong>SplitCriteria</strong> using a String as the key</p>
  
  <pre><code>Map&lt;String, SplitCriteria&gt; criteriaMap = new HashMap&lt;String, SplitCriteria&gt;();
  </code></pre>
  
  <p>A sample SplitCriteria object contains the something like the following:</p>
  
  <pre><code>SplitCriteria [
      id=4, 
      criteriaName="Location", 
      criteriaAbrevName="Loc", 
      fieldName="LOCATION", 
      isMandatory=false
  ]
  </code></pre>
  
  <p>with <strong>id</strong> being a long, <strong>isMandatory</strong> is a boolean and the rest are strings.</p>
  
  <p>I am looping over previously populated Array of the same object type, total count is <strong>7</strong>, adding each to the HashMap using the fieldName attribute as the key:</p>
  
  <pre><code>for(SplitCriteria split : selectedCriteria){
      String fieldName = split.getFieldName();
      criteriaMap.put(fieldName, split);
  }
  </code></pre>
  
  <p>After this loop has finished, the size of the map appears to be <strong>7</strong>, but looking at the table contents there are only <strong>6</strong> objects present.</p>
  
  <p>From researching the issue, I have come to understand that if there is a clash with keys, the clashing objects are "chained" together using the <code>next</code> attribute of the entry in the Map.</p>
  
  <p>From the image below, you can see this is what is happening in my scenario, but the two keys are completely different!</p>
  
  <p><a href="https://i.stack.imgur.com/kFs0x.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kFs0x.png" alt="enter image description here"></a></p>
  
  <p>Also I read this in the docs for the put method </p>
  
  <blockquote>
    <p>If the map previously contained a mapping for the key, the old value is replaced by the specified value</p>
  </blockquote>
  
  <p>and</p>
  
  <blockquote>
    <p>Returns:
    the previous value associated with key, or null if there was no mapping for key.</p>
  </blockquote>
  
  <p>So if the keys were clashing, I would expect the old entry to be returned, but it is not.</p>
  
  <p>I have no clue how this is happening, as each key I am using is completely different to the next.</p>
  
  <p>Any help in resolving this would be greatly appreciated.</p>
  
  <p>Paddy</p>
  
  <p><strong>EDIT:</strong>
  When I try and retrieve the object at a later stage I am getting a null reponse</p>
  
  <pre><code>SplitCriteria criteria = (SplitCriteria) criteriaMap.get(key);
  </code></pre>