Java 如何对地图进行排序和编辑?

Java 如何对地图进行排序和编辑?,java,Java,我有一个付款对象,它有日期和金额字段 List<Payment> 现在,我将按顺序获取这些数据,并将这些数据按排序顺序(日期)放入地图中,如下所示: 1st entry in map: date: 14-01-2018, amount: 10 2nd entry: date: 14-01-2018, amount: 10 date: 16-01-2018, amount: 40(here adding earlier date amount which is 10 for 14-

我有一个付款对象,它有日期和金额字段

List<Payment>
现在,我将按顺序获取这些数据,并将这些数据按排序顺序(日期)放入地图中,如下所示:

1st entry in map:
date: 14-01-2018, amount: 10

2nd entry:
date: 14-01-2018, amount: 10
date: 16-01-2018, amount: 40(here adding earlier date amount which is 10 for 14-01-2018 )

3rd entry:
date: 11-01-2018, amount: 50
date: 14-01-2018, amount: 60 (in 2nd entry for this date amount was 10, but since date 11-01-2018 having amount 50 then i adding 50 to 10)
date: 16-01-2018, amount: 90(same here, as in 2nd entry for this date amount was 40 but need to add 50 of 11-01-2018 as this date is before)

4th entry:
date: 19-01-2012, amount: 30 (since this date will come first i need to add this amount to all later date's amount)
date: 11-01-2018, amount: 80
date: 14-01-2018, amount: 90
date: 16-01-2018, amount: 120

5th entry:
date: 19-01-2012, amount: 30
date: 12-01-2017, amount: 70(this date will come at 2nd place because of sorting, its amount is 70 but it's earlier date 9-01-2012 has amount 30, so need to add that amount and 12-01-2017 amount will become 100, and later date's amount will increase by 70)
date: 11-01-2018, amount: 150
date: 14-01-2018, amount: 160
date: 16-01-2018, amount: 190

您可以只使用排序的映射,例如
TreeMap
,然后将其聚合到:

TreeMap<Date, Double> sum = 
    list.stream()
        .collect(Collectors.groupingBy(Payment::getDate,
                                       TreeMap::new, 
                                       Collectors.summingDouble(Payment::getAmount)
                                      )
                );
TreeMap和=
list.stream()
.collect(收款人)分组方式(付款::getDate,
树映射::新的,
催收员。总和加倍(付款::getAmount)
)
);

向我们展示您的尝试。代码在哪里!?这看起来像是一个家庭作业问题。我不认为给出答案真的有帮助。
TreeMap<Date, Double> sum = 
    list.stream()
        .collect(Collectors.groupingBy(Payment::getDate,
                                       TreeMap::new, 
                                       Collectors.summingDouble(Payment::getAmount)
                                      )
                );