title: Remove items from HashMap by key in java
body: <p>I have one HashMap like this</p>
  
  <pre><code>public static HashMap&lt;String, Integer&gt; jsonPosition = new HashMap&lt;String, Integer&gt;();
  </code></pre>
  
  <p>I put some values like this in my hashmap</p>
  
  <pre><code>GlobalClassParameters.jsonPosition.put("another income",
                          GlobalClassParameters.jsonPosition.size());
  </code></pre>
  
  <p>Now I want to remove the items by their key. I wrote some code that can remove all items with a key equal to some value.</p>
  
  <pre><code>Object objectToRemove = null;
  Iterator&lt;Map.Entry&lt;String, Integer&gt;&gt; iter = GlobalClassParameters.jsonPosition.entrySet().iterator();
  
  while (iter.hasNext()) {
     Map.Entry&lt;String, Integer&gt; entry = iter.next();
  
     if(entry.getKey().equalsIgnoreCase("another income"))
     {
        objectToRemove = entry;
        break;
     }  
  }                               
  
  if(objectToRemove != null)
  {
     GlobalClassParameters.jsonPosition.entrySet().remove(objectToRemove);
  }
  </code></pre>
  
  <p>My problem is that I don't need to remove all objects with keys equal to my "Another Income", but I want to remove only one object with that key.</p>