I have a list I need to iterate over and delete certain items. I can't use an iterator because I need to call methods for each item (such as ls.getStatus()
) which doesn't work with an iterator. If ls.getStatus() == 0
I need to delete that item. How can I avoid the ConcurrentModificationException
?
for (MyList ls : list) {
if (ls.getStatus() == 0) {
ls.run();
list.remove();
} else {
ls.create();
}
}
Thanks