Assume two lists:
List<Integer> list1 = Arrays.asList(1, 2, 3, 4, 5); List<Integer> list2 = Arrays.asList(3, 4, 5, 6, 7);
Using filter()
and collect()
List<Integer> intersection = list1.stream() .filter(list2::contains) .collect(Collectors.toList()); System.out.println(intersection);
Output:
[3, 4, 5]