使用stream对集合进行排序
根据Hash值排序的,无序排序的
List<ModuleVo> moduleList=new ArrayList();
Map<Integer, List<ModuleVo>> collectResult = moduleList.stream().collect(Collectors.groupingBy(ModuleVo::getProjectId));
根据time进行升序排序,如下
TreeMap<Integer, List<ModuleVo>> collectResult = moduleList.stream().collect(Collectors.groupingBy(ModuleVo::getTime,TreeMap::new,Collectors.toList()));
TreeMap默认按照key升序排序
TreeMap<Integer, List<ModuleVo>> collectResult = moduleList.stream().collect(Collectors.groupingBy(ModuleVo::getTime,TreeMap::new,Collectors.toList())).descendingMap();
本文来自博客园,作者:vickcan,转载请注明原文链接:https://www.cnblogs.com/byteexpress/p/18321930

浙公网安备 33010602011771号