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

相关文章:

  • 2022-12-23
  • 2022-01-17
  • 2022-12-23
  • 2021-05-31
  • 2021-08-19
  • 2021-05-23
  • 2022-12-23
猜你喜欢
  • 2022-01-04
  • 2022-12-23
  • 2021-12-01
  • 2022-12-23
  • 2021-10-05
  • 2022-02-04
相关资源
相似解决方案