public static void main(String[] args) {
List<String> list = new ArrayList<String>();
list.add("Value1");
list.add("Value2");
list.add("Value3");
for(String val: list ) {
list.remove(0);
System.out.println(list);
}
}
o\p: [Value2, Value3] Exception in thread "main" java.util.ConcurrentModificationException
Here I am trying to read and remove the 0th element concurrently. So It should give an exception.But My qn is why does it execute the println statements after the exception.The moment it finds the exception it should come out of the loop.