经典指数          
原因
730
浏览数
0
收藏数
 

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 ++;
}

  • it.remove();
  • list.remove(obj);
  • list.remove(index);
  • list.remove(obj,index);

     举报   纠错  
 
切换
1 个答案
答案:A 如果在循环的过程中调用集合的remove()方法,就会导致循环出错,例如: for(int i=0;i
 
切换
撰写答案
扫描后移动端查看本题