且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用Java流获取具有相同最大值的所有对象?

更新时间:2023-02-04 08:48:25

您可以先收集到TreeMap,仅获取最后一个条目(最大值为

You could collect to a TreeMap first and only get the last entry (where the max is)

players.stream()
       .collect(Collectors.groupingBy(
           Player::getPoints,
           TreeMap::new,
           Collectors.toList()
       ))
       .lastEntry()
       .getValue();