我有这样排序的日期列表:如何排序地图<YearMonth,列表<LocalDate>>与Java 8 Lambda和流
2016-07-07
2016-07-08
2016-07-09
2016-07-10
2016-07-11
2016-07-12
2016-07-13
...
2016-07-31
2016-08-01
2016-08-02
2016-08-03
...
2017-01-01
2017-01-02
2017-01-03
...
从这个名单我产生Map<YearMonth, List<LocalDate>>
与流:
Map<YearMonth, List<LocalDate>> d = dates.stream().collect(Collectors.toList())
.stream().collect(Collectors.groupingBy(date -> YearMonth.from(date)));
该地图的输出是这样的:
{2016-12=[2016-12-01, 2016-12-02,...2016-12-31], 2016-11=[2016-11-01, 2016-11-02,...]}
但我需要的输出应该是这样的:
- 地图的关键日期升序排序:
{2016-07=[...], 2016-08=[...]}
- 按日期升序排序图(表)的价值:
{2016-07=[2016-07-01, 2016-07-02, ...], 2016-08=[2016-08-01, 2016-08-02, ...]}
我试着很多选项来得到我的预期结果,但我只是得到正确的排序的关键或价值,而不是两个:
Map<YearMonth, List<LocalDate>> m = stream().collect(Collectors.toList())
.stream().sorted((e1,e2) -> e2.compareTo(e1))
.collect(Collectors.groupingBy(date -> YearMonth.from(date)));
结果:
{2016-07=[2016-07-31, 2016-07-30, ...], 2016-08=[2016-08-31, 2016-08-30, ...]}
我如何排序都是由键和值?
工程完美。谢谢 – Patrick