根据 java doc Java.util.ArrayList 在创建迭代器后更改它的数据结构时会抛出 concurrentModificationException ,但是当我在下面运行代码时它不会抛出相同的
ArrayList<Employee> lsEmp=new ArrayList<Employee>();
Employee indra = new Employee(101,"Indra");
Employee ankit =new Employee(102,"Ankit");
Employee bhanu= new Employee(103,"bhanu");
lsEmp.add(indra);
lsEmp.add(ankit);
//lsEmp.add(bhanu);
System.out.println("Employee list"+lsEmp);
Iterator<Employee> it =lsEmp.iterator();
if (it.hasNext()){
Employee temp = it.next();
if(temp.getName().equalsIgnoreCase("Indra"));{
System.out.println("inside if condition");
//temp.setName("Indra Mohan Joshi");
lsEmp.remove(temp);
lsEmp.add(bhanu);
}
}
System.out.println("list after loop"+lsEmp);
你能帮我理解这背后的逻辑吗?提前致谢 !