title: Iterator differences between JDK 1.6 and 1.7
body: <p>I'm having an issue with the same code running on two different versions of the JDK. 
  The code basically has nested iterators on the same HashMap. 
  The following is pseudocode. I've inherited this code...</p>
  
  <pre><code>Iterator entries = source.entrySet().iterator();
  while(entries.hasNext()) {
      Map.Entry entry = entries.next();
  
      Iterator otherEntries = source.entrySet().iterator();
      while(otherEntries.hasNext()) {
          Map.Entry otherEntry = otherEntries.next();
          List elements = otherEntry.getValue();
  
          for(element : elements) {
              ...
          }
  
          for(someOtherElement : someOtherElement) { 
              if(...) {
                  elements.add(someOtherElement);
              }
          }
      }
  }
  </code></pre>
  
  <p>Apologies for the mess of this code but as I mentioned I inherited this.
  This code runs fine for us in JDK 1.7.
  In JDK 1.6 (an IBM RSA JDK), the call to "elements.add(...)" also adds the elements to the original "source" HashMaps elements. The "elements" List comes from otherEntry.getValue(). Adding or updating elements seems to cause the source to be updated as it is passed by reference.
  However, in JDK 1.7 (just a standard one), we don't see the same behaviour. Here calls to "elements.add" do not update or modify the "source" HashMap.</p>
  
  <p>So I'm trying to understand whats going on here and is this something that was changed between JDK's??</p>
  
  <p>Thanks</p>