场景:
项目要做价格排名。数据库存的是json ,没法算。在java层面转map 再计算
两个要点:
1、流不支持map直接操作,支持list直接操作
2、我们一般的map可以分解为多个entrySet
结论:
一个map可以分解为一个
List<Map.Entry<Long, BigDecimal>
再用 list.stream()水到渠成
List<Long> collect = map.entrySet().stream()//这里就是一个list<>
.sorted(Comparator.comparing(o -> o.getValue().doubleValue()))//在这排序
.map(o->o.getKey())//这里映射,业务上要的是key
.collect(Collectors.toList());//转数组结果集