~/ learn/ comp-308/ cards/ List, ArrayList, LinkedList & iteration
1 of 5

Greenhouse Controller: iterate a copy, remove from the original

Greenhouse Controller: iterate a copy, remove from the original

Answer

for (Event e : new ArrayList<Event>(eventList)) if (e.ready()) { e.action(); eventList.remove(e); }

The for-each walks a fresh copy of eventList that is never modified, so no iterator over eventList is active; eventList.remove(e) safely shrinks the original. This is the project's exact CME-avoidance pattern.

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/f18ed4fa-9592-4f37-9968-d0069ddd3033/flashcard utf-8 LF