java 两个list 取出交集

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

 

posted on 2022-11-08 07:34  小目标青年  阅读(13)  评论(0编辑  收藏  举报