The problem is that you’re trying to access (meaning iterate) the collection while it is being changed (you’re adding or removing elements).
Code below is just scratch.
This can be due to:
for(collection iteration)
if(x)
remove element // add element
You can solve this by:
copyOfArray = originalArray.copy
for(originalArray iteration)
if(x)
do something (copyOfArray.remove or copyOfArray.add)
if you need to change the other array, just copy the copyOfArray to the original array.
I had the same problem and I solved this using the strategy above.
If you still have any trouble, when I get home I’ll post the code.