Iterator it = postViewList.iterator();
while(it.hasNext()){
AdjustPlanNumVO voo = (AdjustPlanNumVO)it.next();
if(voo.getNeedNum() <= 0){
postViewList.remove(voo);
// it.remove();
}
}
在遍历list的时候remove,这是报错java.util.ConcurrentModificationException。
应该用it.remove();这样就删除了对应号得list中的内容。
Iterator it = postViewList.iterator();
while(it.hasNext()){
AdjustPlanNumVO voo = (AdjustPlanNumVO)it.next();
if(voo.getNeedNum() <= 0){
it.remove();
}
}

本文介绍了一种在Java中正确地从List中移除元素的方法,避免了在遍历过程中直接调用list.remove()导致的java.util.ConcurrentModificationException异常。
630

被折叠的 条评论
为什么被折叠?



