一个选择题,不明白,求指教
list是一个ArrayList的对象,哪个选项的代码填写到//todo delete处,可以在Iterator遍历的过程中正确并安全的删除一个list中保存的对象?( )
Iterator it = list.iterator();
int index = 0;
while (it.hasNext()){
Object obj = it.next();
if (needDelete(obj)) { //needDelete返回boolean,决定是否要删除
//todo delete
}
index ++;
}
A)list.remove(obj);
B)list.remove(index);
C)list.remove(it.next());
D)it.remove();
选择什么?为什么?