title: While iterating over a collections of Java objects--how can I mutate current object?
body: <p>I will be using an iterator to loop through a collection of objects in Java. I am a little confused about using an Iterator however (used to using for each loop).  let say I have code like this:</p>
  
  <pre><code>Iterator&lt;Organization&gt; orgIter = orgs.iterator();
  while (orgIter.hasNext()) {
      Organization orgObj = orgIter.next();
      orgObj.setChildOrgsTree(generateOrgChildTree(orgObj, new ArrayList&lt;Organization&gt;()));
  }
  </code></pre>
  
  <p>I create a new object and then change the fields inside the object.  My plan was to then set the original object I formed the iteroter out equal to a List of this Object that I create (List is not shown above, but I just figured out that I would need it).  </p>
  
  <p>But it would be so much easier if I didn't have to create a new Object to do all of this. Is there a way I can get the current object and mutate that?</p>