public class Message { private int id; private User sender; private User receiver; private String text; private Date senddate; .. }
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()));