0

I am getting the following error

java purse transfer method giving Exception in thread "main" java.util.ConcurrentModificationException error

when executing the following method:

public void transfer1(Purse p) {
    for (String coin : newPurse) {
        newPurse.add(coin);
        p.newPurse.clear();
    }
}
ctst
  • 1,610
  • 1
  • 13
  • 28
vras
  • 1
  • 2
    Possible duplicate of [Concurrent Modification Exception : adding to an ArrayList](http://stackoverflow.com/questions/6866238/concurrent-modification-exception-adding-to-an-arraylist) – radoh Mar 04 '16 at 16:08
  • This comes because you want to make changes in the list, you are currently iterating over. You can do this with an iterator, but not with an forEach loop. Also I am not quite sure, what you want to accomplish with your code. Look at the linked question from radoh. – ctst Mar 04 '16 at 16:13
  • Possible duplicate of [Concurrent Modification exception](http://stackoverflow.com/questions/1496180/concurrent-modification-exception) – fabian Mar 04 '16 at 23:20

0 Answers0