[Solved] Comparing two list of objects and forming a new list by comparing one property of two list in java 8 [closed]


You want intersection of the list while saving of first list type.

Get the common field values in the Set.

valuesToCheck=secondList.stream().map(SecondListObject::commonFiled).collect(Collectors.toList);

”’

Apply a stream on the first while filtering based on the matching common field value in the set built in the previous step.

firstList.stream().filter(x->valuesToCheck.contains(x.getCommonFiled)).collect(toList)

You got the gist.

1

solved Comparing two list of objects and forming a new list by comparing one property of two list in java 8 [closed]