Duplicate :
|
ADDITIONAL SYSTEM INFORMATION : It is reproducible in all environments A DESCRIPTION OF THE PROBLEM : When we remove second last element from the list using remove method of list while iterating over the list,it doesn't throw ConcurrentModificationException although it should throw STEPS TO FOLLOW TO REPRODUCE THE PROBLEM : Create a list and then add some elements into it and now iterate over a list and put a if condition in the loop for second last element and now remove that element using remove method of list,it should throw concurrentmodificationexception but it's not throwing EXPECTED VERSUS ACTUAL BEHAVIOR : EXPECTED - The above steps should throw ConcurretModificationException but it is not throwing ACTUAL - No ConcurrentModificationException ---------- BEGIN SOURCE ---------- public static void main(String args[]) { List<String> myList = new ArrayList<String>(); myList.add("1"); myList.add("2"); myList.add("3"); myList.add("4"); myList.add("5"); myList.add("6"); Iterator<String> lii = myList.iterator(); while (lii.hasNext()) { String el = lii.next(); if (el.equals("5")) { myList.remove("5"); } } } ---------- END SOURCE ---------- FREQUENCY : always