title: Valid iterator on a removed list?
body: <p>I wrote some code that works but I'm not sure. Consider</p>
  
  <pre><code>LinkedList&lt;Iterator&lt;Integer&gt;&gt; iterators;
  HashMap&lt;Character, TreeSet&lt;Integer&gt;&gt; map;
  for (char c : map.keySet()) {
      iterators.add(map.get(c).iterator());
      map.remove(c);
  }
  </code></pre>
  
  <p>Even though the original TreeSet has been removed, the iterator seems to work fine (i.e. goes in the original ordering of the TreeSet). I don't quite understand why it's functional--it seems as though there's passing-by-value here instead of passing-by-reference. However, obviously, if I were to write</p>
  
  <pre><code>map.get(c).add(6);
  </code></pre>
  
  <p>the TreeSet would actually add 6 in the map (not just add 6 to a copy of the TreeSets in the map), indicating get is passing by reference. Can someone help clear up the confusion here?</p>