I am deleting 2nd last element of an ArrayList while iterating the same list through enhanced for-loop and I was expecting a ConcurrentModificationException however it is working fine. Kindly help me if java has provided a special case for 2nd last element.
I tried it with different indexes but it is working as expected only for the 2nd last element, it is giving unexpected result
List<Integer> list=new ArrayList<>();
list.add(2);
list.add(4);
list.add(3);
list.add(5);
for(Integer num:list) {
if(num==3) {
list.remove(num);
}
System.out.println(num);
}
Expected result: ConcurrentModificationException
Actual Result: Working fine