Java 8 Stream API toMap converting to TreeMap

后端 未结 2 1633
耶瑟儿~
耶瑟儿~ 2021-02-05 17:35
public class Message {
    private int id;
    private User sender;
    private User receiver;
    private String text;   
    private Date senddate;
..
}
2条回答
  •  执念已碎
    2021-02-05 18:03

    If your list is sorted then just use this code for sorted map.

    Map> pMonthlyDataMap = list
                    .stream().collect(Collectors.groupingBy(WdHour::getName, TreeMap::new, Collectors.toList()));
    

提交回复
热议问题