可能重复:
关于并发修改异常
我在下面的代码中遇到了这个并发修改异常错误,因为我试图在迭代时删除元素..代码在下面..
List list=new ArrayList ();
list.add(new Emp("Saral","Trainer",34500));
list.add(new Emp("Saral","Trainer",36000));
list.add(new Emp("Saral","Trainer",33000));
list.add(new Emp("Sachin","Programmer",24000));
我检索的方式是..
System.out.println("Content of list are : ");
ListIterator itr1=list.listIterator();
while(itr1.hasNext())
{
list.add(new Emp("Anand","Manager",56000)); //
Emp e=(Emp)itr1.next();
e.display();
}
您能否建议如何避免此错误..?