Java stream that is distinct by more than one property
问题 I have following objects in the stream: class Foo{ String a; String b; int c; } I would like to filter a stream based on following criteria: eg. Having entries in stream: foo1 and foo2 : foo1 and foo2 have same values for a and b , but they differ in c property. I would like to get rid of entries that have c higher in such case. 回答1: Semantically equivalent to Eugene’s answer, but a bit simpler: List<Foo> foos = Stream.of(new Foo("a", "b", 1), new Foo("a", "b", 2), new Foo("a", "b", 3), new