Java8 stream根据字段分组并排序

Java8 stream根据字段分组并排序

1.根据字符串类型日期分组,并按照日期升序排序,返回TreeMap,map的key为字符串日期,value为list

ArrayList records = plnExectionRecordMapper.selectRecord(ids[i]);
TreeMap> collect =  records.stream().collect(Collectors.groupingBy(PlnexecutionRecord :: getDtate,TreeMap::new,Collectors.toList()));

2.将value中的list按照时间早晚排序

Set>> entrySet = collect.entrySet();
for(Entry> entry : entrySet){
    List sortedList =  entry.getValue().stream().sorted(Comparing.comparing(PlnexecutionRecord :: getTime)).collect(Collectors.toList());
}

你可能感兴趣的:(工作笔记,java)