List list = new ArrayList();
list.add("1");
list.add("2");
list.add("3");

ListIterator<String> it = list.listIterator();
while (it.hasNext()) {
String x = it.next();
if (x.equals("2")) {
it.remove();
}
}

Iterator<String> it = list.Iterator();
while (it.hasNext()) {
String x = it.next();
if (x.equals("2")) {
it.remove();
}
}


下面写法不正确,不建议使用:
list.stream().forEach(
e -> {
if (e.equals("1")) {
list.remove(e);
}
}
);

for循环和forEach循环也是不对的
 posted on 2019-08-29 20:40  sunnyBalckCat  阅读(3208)  评论(1编辑  收藏  举报