-
原因
在Java中,使用增强for循环(也称为for-each循环)遍历一个列表,并在遍历时删除其中的元素是一个常见的错误,因为它会导致并发修改异常(ConcurrentModificationException)。举例:Listlist = new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5, 6)); for (Integer num : list) { if (num % 2 == 0) { list.remove(num); } } -
源码分析
