get intersection of two lists java code example
Example: get intersection of two lists java
Set result = list.stream() .distinct() .filter(otherList::contains) .collect(Collectors.toSet()); Set commonElements = new HashSet(Arrays.asList("red", "green")); Assert.assertEquals(commonElements, result);