I have the following code:
List<MyObject> filteredObjects = myObjects.stream()
.filter(anObject ->
Collections.frequency(myObjects, anObject) > 1
)
.collect(Collectors.toList());
Which does the job of getting me the objects from the Collection of MyObject that occur more than once.
I need to modify this code so that it gives me the objects that match one another not according to the equals(), but based on a subset of properties.
So if MyObject has properties: foo, bar and baz.
public static class MyObject {
private Foo foo;
private Bar bar;
private Baz baz;
// constructor, getters, etc.
}
I want the to get the objects that have a corresponding object in the collection with the same values of foo and bar.