删除集合方法
public static void main(String[] args) {
ArrayList<Integer> arrayList = new ArrayList();
arrayList.add(1);
arrayList.add(2);
arrayList.add(3);
arrayList.add(4);
Iterator<Integer> iterator = arrayList.iterator();
while (iterator.hasNext()) {
Integer next = iterator.next();
if (next == 1) {
iterator.remove();
}
}
}
ArrayList<Integer> arrayList = new ArrayList();
arrayList.add(1);
arrayList.add(2);
arrayList.add(3);
arrayList.add(4);
List<Integer> integerStream = arrayList.stream().filter(item -> {
return item > 2;
}).collect(Collectors.toList());
System.out.println(integerStream);
ArrayList<Integer> arrayList = new ArrayList();
arrayList.add(1);
arrayList.add(2);
arrayList.add(3);
arrayList.add(4);
arrayList.removeIf(x -> x > 2);
标签:iterator,删除,ArrayList,next,add,集合,new,方法,arrayList
From: https://www.cnblogs.com/jichenghui/p/18358998