removeIf is a single call that cannot throw ConcurrentModificationException, unlike removing inside an enhanced for loop.
var nums = new ArrayList<>(List.of(1, 2, 3, 4, 5, 6));
nums.removeIf(n -> n % 2 == 0);
System.out.println("after removeIf(even): " + nums);
var names = new ArrayList<>(List.of("Ava", "Bo", "Cara", "Di"));
names.removeIf(s -> s.length() <= 2);
System.out.println("after removeIf(short): " + names);
after removeIf(even): [1, 3, 5]
after removeIf(short): [Ava, Cara]
Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.
Published 2026-07-30