更新时间:2022-06-10 18:38:22
从列表中删除元素
objectA.removeIf(x - >条件);
objectA.removeIf(x -> conditions);
例如:
objectA.removeIf(x - > blockedWorkerIds.contains(x));
eg: objectA.removeIf(x -> blockedWorkerIds.contains(x));
List<String> str1 = new ArrayList<String>();
str1.add("A");
str1.add("B");
str1.add("C");
str1.add("D");
List<String> str2 = new ArrayList<String>();
str2.add("D");
str2.add("E");
str1.removeIf(x -> str2.contains(x));
str1.forEach(System.out::println);
输出:
A
B
C
OUTPUT: A B C