单选题:Given list an object of ArrayList, which code below for //todo d
Given list an object of ArrayList, which code below for //todo delete can remove an element in the list correctly and safely? @[D](2)
```Java
Iterator it = list.iterator();
int index = 0;
while (it.hasNext()){
Object obj = it.next();
if (needDelete(obj)) { // returns Boolean for removing or not
//todo delete
}
index ++;
}
```
A. list.remove(obj);
B. list.remove(index);
C. list.remove(it.next());
D. it.remove();
A.list.remove(obj);
B.list.remove(index);
C.list.remove(it.next());
D.it.remove();
答案:D
```Java
Iterator it = list.iterator();
int index = 0;
while (it.hasNext()){
Object obj = it.next();
if (needDelete(obj)) { // returns Boolean for removing or not
//todo delete
}
index ++;
}
```
A. list.remove(obj);
B. list.remove(index);
C. list.remove(it.next());
D. it.remove();
A.list.remove(obj);
B.list.remove(index);
C.list.remove(it.next());
D.it.remove();
答案:D