I know that when you iterate over an arraylist with a forech loop, and then trying to remove an object from it, the concurrent modification exception is thrown. I have the following code, which produces this exception whenever I try to remove any of the list's objects.....except for the object "D". whenever I try to remove this object, there is NO EXCEPTION thrown. can someone please tell me why there is no exception? this is my code:
List<String> myList = new ArrayList<>();
myList.add("A");
myList.add("B");
myList.add("C");
myList.add("D");
myList.add("E");
for (String s: myList) {
if (s.equals("D")) {
myList.remove("D");
}
}
System.out.println(myList);