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循环也是不对的