java 两个list 取出交集

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

        List accountIdListTwo = new ArrayList<>();
        accountIdListTwo.add(3);
        accountIdListTwo.add(4);
        accountIdListTwo.add(5);
        accountIdListTwo.add(6);
        
        
        List accountIdList = accountIdListOne.stream().filter(accountIdListTwo::contains).collect(Collectors.toList());
        
        System.out.println(accountIdList.toString());

 

你可能感兴趣的:(Java,java,list,交集)