I'm studying for java 8 certification, and I discovered an incredible thing!
I'm attending a course, during explanation about List in Java he talk about ConcurrentModificationException.
Look at this fragment:
List<String> lista = new LinkedList<>();
lista.add("d");
lista.add("d");
lista.add("d");
lista.add("d");
for(int i = 0; i<lista.size(); i++){
System.out.println(lista.get(i));
}
for(String s : lista){
lista.add(s);
}}
Why java without ITERATOR throw ConcurrentModificationException?
Should not the list be read from the first cycle, and only once it has finished with the first one start with the second?
How can the second loop be executed while the first is still iterating?