title: Java: Changing the properties of an iterable object while iterating over it
body: <p>The following code is just to produce an example of the problem:</p>
  
  <pre><code> public static void main(String[] args) {
    Collection&lt;Integer&gt; src = new ArrayList&lt;Integer&gt;();
    Collection&lt;Integer&gt; dest = new ArrayList&lt;Integer&gt;();
  
    src.add(2);
    src.add(7);
    src.add(3);
    src.add(2201);
    src.add(-21);
  
    dest.add(10);
  
    while (src.size() != 0) {
     for (int i : dest) {
      int min = Collections.min(src);
      dest.add(min);
      src.remove(min);
     }
    }
  
   }
  </code></pre>
  
  <p>What I want to do is move everything from src to dest in a specific order. (Here, it's what is the minimum value, but that's just a simplification from my real problem.) However, I am modifying dest while iterating over it, and get the following error:</p>
  
  <pre><code>Exception in thread "main" java.util.ConcurrentModificationException
   at java.util.AbstractList$Itr.checkForComodification(Unknown Source)
   at java.util.AbstractList$Itr.next(Unknown Source)
   at nth23.experimental.MoveBetweenSets.main(MoveBetweenSets.java:25)
  </code></pre>
  
  <p>How can I get around this?</p>