删除集合元素的方法

使用for循环遍历集合时,循环体不能删除集合的内容;可使用使用迭代器来移除集合元素

List<String> a = new ArrayList<>();
a.add("1");
a.add("2");
Iterator<String> it = a.iterator();
while(it.hasNext()){
    String temp = it.next();
    if(删除元素的条件){ i
        t.remove();
    }
}

posted on 2017-08-09 14:23  巴比龙  阅读(352)  评论(0编辑  收藏  举报

导航