Java8 stream根據字段分組並排序
1.根據字符串類型日期分組,並按照日期升序排序,返回TreeMap<String,List>,map的key爲字符串日期,value爲list
ArrayList<PlnexecutionRecord> records = plnExectionRecordMapper.selectRecord(ids[i]);
TreeMap<String,List<PlnexecutionRecord>> collect = records.stream().collect(Collectors.groupingBy(PlnexecutionRecord :: getDtate,TreeMap::new,Collectors.toList()));
2.將value中的list按照時間早晚排序
Set<Entry<String,List<PlnexecutionRecord>>> entrySet = collect.entrySet();
for(Entry<String,List<PlnexecutionRecord>> entry : entrySet){
List<PlnexecutionRecord> sortedList = entry.getValue().stream().sorted(Comparing.comparing(PlnexecutionRecord :: getTime)).collect(Collectors.toList());
}