How to avoid "ConcurrentModificationException" while removing elements from `ArrayList` while iterating it? [duplicate]
As an alternative to everyone else's answers I've always done something like this:
List<String> toRemove = new ArrayList<String>();for (String str : myArrayList) { if (someCondition) { toRemove.add(str); }}myArrayList.removeAll(toRemove);
This will avoid you having to deal with the iterator directly, but requires another list. I've always preferred this route for whatever reason.