Skip to main content
๐Ÿ› Bug HuntJV Java Hard+35 XP

ConcurrentModificationException

This crashes when removing items while iterating.

๐Ÿ› Find the bug
1List<String> items = new ArrayList<>(Arrays.asList("a", "b", "c"));
2for (String item : items) {
3 if (item.equals("b")) {
4 items.remove(item);
5 }
6}
๐Ÿ› The bug is on line 4

๐Ÿ”ง Select the correct fix:

Priygop - Leading Professional Development Platform | Expert Courses & Interview Prep