Answers for "intersection of two lists in java 8"

0

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);
Posted by: Guest on July-30-2020
0

intersection of two lists using set method

# Python program to illustrate the intersection
# of two lists using set() method
def intersection(lst1, lst2):
    return list(set(lst1) & set(lst2))
 
# Driver Code
lst1 = [15, 9, 10, 56, 23, 78, 5, 4, 9]
lst2 = [9, 4, 5, 36, 47, 26, 10, 45, 87]
print(intersection(lst1, lst2))
Posted by: Guest on December-27-2021

Code answers related to "intersection of two lists in java 8"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language