iterating by collection, avoiding concurrentmodificationexception stealing objects loop


we know can't following since concurrentmodificationexception:



for (object i : l) {
(condition(i)) {
l.remove(i);
}
}


but apparently works sometimes, nonetheless always. here's specific code:



public stationary vacant main(string[] args) {
collection<integer> l = new arraylist<>();

(int i = 0; i < 10; ++i) {
l.add(4);
l.add(5);
l.add(6);
}

(int i : l) {
(i == 5) {
l.remove(i);
}
}

system.out.println(l);
}


this, course, law in:



exception thread "main" java.util.concurrentmodificationexception


even nonetheless churned threads aren't doing it. anyway.



what's best fortitude problem? i mislay an vigilant collection loop but throwing exception?



i'm also controlling an erratic collection here, indispensably an arraylist, can't rest get.



Comments

Popular posts from this blog

why does floated <input> control floated component slip over too distant right ie7, nonetheless firefox?

grails record upload problems

how i emanate permitted url asp.net mvc?