Java concurrency iterator arraylist shenanigans
I have some code that uses an iterator to traverse an arraylist. If a certain condition is met, I want to add an object to the arraylist. Can this be done with an iterator? Or do I need to just use a loopedy loop?
<pre><code>
itr=particleArr.iterator();
while (itr.hasNext()){
    particle=itr.next();
    if (isMyLifeUtterlyMeaningless)) {
         particleArr.add(new Particle(particle.getXCoor() - 5,
             particle.getYCoor() + 5,
             colorState));
}}
</pre></code>
which throw a modification exception. So how do I rewrite this with the iterator?
Java concurrency iterator arraylist shenanigans
===

I have some code that uses an iterator to traverse an arraylist. If a certain condition is met, I want to add an object to the arraylist. Can this be done with an iterator? Or do I need to just use a loopedy loop?
<pre><code>
itr=particleArr.iterator();
while (itr.hasNext()){
    particle=itr.next();
    if (isMyLifeUtterlyMeaningless)) {
         particleArr.add(new Particle(particle.getXCoor() - 5,
             particle.getYCoor() + 5,
             colorState));
}}
</pre></code>
which throw a modification exception. So how do I rewrite this with the iterator?