Collections Beginner

Collection bulk operations instead of mutation loops

Use removeIf(), replaceAll(), and List.sort() for direct collection transformations.

✕ Iterator mutation loop
for (Iterator<Order> it = orders.iterator(); it.hasNext();) {
    if (it.next().cancelled()) {
        it.remove();
    }
}
✓ Java 8+
orders.removeIf(Order::cancelled);
See a problem with this code? Let us know.
👁

Clear intent

The operation describes what changes, not how to iterate.

🐛

Safer mutation

Avoids manual iterator-removal rules.

⚡

Less code

Common transformations become a single expression.

Old Approach
Manual iterator removal
Modern Approach
Collection.removeIf()
Since JDK
8
Difficulty
Beginner
Collection bulk operations instead of mutation loops
Available

Available since JDK 8 (March 2014)

Modern collection interfaces expose common mutations directly. Methods such as removeIf(), replaceAll(), and List.sort() replace control-flow-heavy loops with operations that state the intended transformation.