【发布时间】:2021-11-11 15:45:27
【问题描述】:
我有一堂课PlayerAndCountry:
class PlayerAndCountry {
private Country country;
private Player player;
}
还有一个List<PlayerAndCountry>
我想要这样的最终地图:Map<Country,List<Player>>
我知道如何获取Map<Country, List<PlayerAndCountry>>,但不知道Map<Country,List<Player>>
【问题讨论】:
-
list.stream().collect(groupingBy(PlayerAndCountry::getCountry, mapping(PlayerAndCountry::getPlayer, toList())));这里,Collectors是静态导入:import static java.util.stream.Collectors.*;
标签: java java-8 java-stream