hc学习平台

 找回密码
 立即注册
搜索
热搜: 活动 交友 javakc
 › XIAOSONG › 日志

list是一个ArrayList的对象,哪个选项的代码填写到//todo delete处,可以在Iterator遍历的过程中正确并安全的删除一个list中保存的对象  

2022-08-09 13:55:58 查看(186) 回复(0)

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、it.remove();
D、list.remove(it.next());
C

评论 (0 个评论)

facelist

全部作者的其他最新日志



站点统计|举报|Archiver|手机版|小黑屋|Comsenz Inc.

GMT+8, , Processed in 0.195171 second(s), 9 queries .

Powered by javakc! X1.0

© 2004-2014 javakc

f1208.com 备案号:京ICP备14030918号-1

返回顶部