If you just need to check the basic equality, this can be done using the basic JDK without changing the input lists in one line
!Collections.disjoint(list1, list2);
If you need to check a specific property, this is more complicated. I would recommend, by default,
list1.stream() .map(Object1::getProperty) .anyMatch( list2.stream() .map(Object2::getProperty) .collect(toSet()) ::contains)
... which collects individual values ββin list2 and checks each value in list1 for availability.
Louis Wasserman Aug 03 '12 at 15:59 2012-08-03 15:59
source share