Также имеется исключение ConcurrentModificationException для CopyOnWriteArrayList
Я использую следующий код, чтобы создать CopyOnWriteArrayList, изменить элементы, находящиеся в нем, а затем распечатать элементы. Я не могу понять, почему я получаю ConcurrentModificationException, когда я использую CopyOnWriteArrayList.
public class Solution {
public static int main() {
CopyOnWriteArrayList<Integer> arrList = new CopyOnWriteArrayList<>();
//fill the array list;
List<Integer> sublist = arrList.sublist(startIndex, endIndex);
arrList.removeAll(sublist);
arrList.addAll(sublist); //here is where the ConcurrentModificationException comes and I dont understand why
//iterate and print the elements of the list.
}
}