stationMap = peopleList.stream().collect(Collectors.groupingBy(People::getJgId));
stationMap = peopleList.stream().collect(Collectors.groupingBy(People::getJgId,TreeMap::new,Collectors.toList())).descendingMap();
TreeMap默认按照key升序排序,collectPlan.descendingMap()可以进行降序排序
List<People> peopleList = Lists.newArrayList();
peopleList.add(new People(1, "小王", 5));
peopleList.add(new People(1, "小李", 4));
peopleList.add(new People(2, "小张", 3));
peopleList.add(new People(2, "小皇", 2));
peopleList.add(new People(2, "小刘", 1));
//分组排序并加序号
Map<Integer, List<People>> stationMap = new HashMap<Integer, List<People>>();
// 使用stream流将list转为map,key为指定字段的值
stationMap = peopleList.stream().collect(Collectors.groupingBy(People::getJgId));
log.info(stationMap.toString());
stationMap = peopleList.stream().collect(Collectors.groupingBy(People::getJgId,TreeMap::new,Collectors.toList())).descendingMap();
log.info(stationMap.toString());