对List<Map<String,Object>> 排序
List<Map<String, Object>> num = resourceChange.stream().sorted(Comparator.comparing(map -> map.get("num").toString())).collect(Collectors.toList());
//降序可以不加
Collections.reverse(num);
对普通实体类排序
patrolArea= patrolArea.stream().sorted(Comparator.comparing(PatrolAreaVo::getAreacode)).collect(Collectors.toList());
//倒叙
patrolArea= patrolArea.stream().sorted(Comparator.comparing(PatrolAreaVo::getAreacode).reversed()).collect(Collectors.toList());
//2.1)、找到所有的一级分类
List<CategoryEntity> level1Menus = entities.stream().filter(categoryEntity ->
categoryEntity.getParentCid() == 0
).map((menu)->{
menu.setChildren(getChildrens(menu,entities));
return menu;
}).sorted((menu1,menu2)->{
return (menu1.getSort()==null?0:menu1.getSort()) - (menu2.getSort()==null?0:menu2.getSort());
}).collect(Collectors.toList());
本文介绍如何使用Java 8 Stream API对List<Map<String,Object>>及实体类进行排序操作,包括升序与降序,并展示了如何对分类菜单进行排序并获取其子菜单。
5887

被折叠的 条评论
为什么被折叠?



