List<String> list= Arrays.asList("DQR", "DBH", "BFBH");
List<String> removeStates = Arrays.asList("DQR");
1、第一种方法使用removeIf()
list.removeIf(l -> removeStates.contains(l));
2、第二种方法使用迭代器iterator
Iterator<String> iterator = list.iterator();
while (iterator.hasNext()) {
String state = iterator.next();
if (removeStates.contains(state)) {
iterator.remove();
}
}
Java集合(List)删除元素
于 2024-10-10 16:33:14 首次发布