title: Java HashMap Removing Key/Value
body: <p>I'm just looking for an explanation and/or insight as to why its better to iterate over a HashMap.</p>
  
  <p>For instance the code below (in my eyes) does the exact same (or it should). However if I don't iterate over the HashMap the key is not removed.</p>
  
  <pre><code>_adjacentNodes.remove(node);        
  
  Iterator&lt;Map.Entry&lt;String, LinkedList&lt;Node&gt;&gt;&gt; iterator = _adjacentNodes.entrySet().iterator();
  while (iterator.hasNext()) {
       Map.Entry&lt;String, LinkedList&lt;Node&gt;&gt; entry = iterator.next();
       if(node.getNodeID().contentEquals(entry.getKey())){
            iterator.remove();
       }
  }
  </code></pre>
  
  <p>What is going on?</p>