Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

get intersection of two lists 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);
Source by www.baeldung.com #
 
PREVIOUS NEXT
Tagged: #intersection #lists #java
ADD COMMENT
Topic
Name
4+2 =