List<Integer> accountIdListOne = new ArrayList<>();
accountIdListOne.add(1);
accountIdListOne.add(2);
accountIdListOne.add(3);
accountIdListOne.add(4);
List<Integer> accountIdListTwo = new ArrayList<>();
accountIdListTwo.add(3);
accountIdListTwo.add(4);
accountIdListTwo.add(5);
accountIdListTwo.add(6);
List<Integer> accountIdList = accountIdListOne.stream().filter(accountIdListTwo::contains).collect(Collectors.toList());
System.out.println(accountIdList.toString());
结果:
3
4
账户ID交集:Java Stream操作过滤AccountId
本文展示了如何使用Java 8的Stream API从两个列表中筛选出共同的账户ID,仅保留存在于两个列表中的元素。通过`filter`和`contains`方法实现结果为3和4。
2512

被折叠的 条评论
为什么被折叠?



