Dapatkan persimpangan dua daftar java

Set<String> result = list.stream()  .distinct()  .filter(otherList::contains)  .collect(Collectors.toSet()); Set<String> commonElements = new HashSet(Arrays.asList("red", "green")); Assert.assertEquals(commonElements, result);
Combative Corncrake