java 两个list 取出交集

阅读 85

2022-08-02


List<Integer> accountIdListOne = new ArrayList<>();
accountIdListOne.add(1);
accountIdListOne.add(2);
accountIdListOne.add(3);

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());

 

精彩评论(0)

0 0 举报