ArrayList<Integer> listA = new ArrayList<>(); ArrayList<Integer> listB = new ArrayList<>(); listA.add(2); listA.add(3); listA.add(8); System.out.println("**this is listA*********"+listA); listB.add(3); listB.add(8); listB.add(9); System.out.println("**this is listB*********"+listB); List<Integer> intersectionList =listA.stream().filter(t->listB.contains(t)).collect(Collectors.toList()); System.out.println("集合的交集"+intersectionList); List<Integer> ListARomoveB =listA.stream().filter(t-> !listB.contains(t)).collect(Collectors.toList()); System.out.println("a去除b的差集"+ListARomoveB); List<Integer> ListBRomoveA =listB.stream().filter(t-> !listA.contains(t)).collect(Collectors.toList()); System.out.println("b去除a的差集"+ListBRomoveA);