Given the following class (simplified for the question):
public static class Match {
private final String type;
private fina
I have two methods for you.
A possible implementation is to use Collectors.toMap() to answers your problem.
stream.collect(Collectors.toMap(Match::getType, Match::getScore, Math::max));
And if you prefer to get a List, you can remap the result
stream
.collect(Collectors.toMap(Match::getType, Match::getScore, Math::max))
.entrySet()
.stream()
.map(e -> new Match(e.getKey(), e.getValue()))
.collect(Collectors.toList());
Like you say in your question, it is possible to extract this logic in a custom collector. You can do it like this:
public class MaxMatch implements Collector, List> {
@Override
public Supplier
and use it like this:
stream.collect(new MaxMatch());
Hope this help you :)