我有一堂课叫Info
public class Info {
private String account;
private String opportunity;
private Integer value;
private String desc;
}
我想Info
按两个字段(帐户和机会)对列表进行分组,然后根据值对其进行排序。即分组排序前的信息列表:
List<Info> infos = [(account = 1234, opportunity = abs, value = 4, desc= test),
(account = 1234, opportunity = abs, value = 5, desc = testing),
(account = 1234, opportunity = abss, value = 10, desc = vip),
(account = 123, opportunity = abss, value = 8, desc = vip),
(account = 12, opportunity = absddd, value = 4, desc = production),
(account = 12, opportunity = absooo, value = 2, desc = test)]
分组排序后我期望的结果,
Map<String, Map<String, List<Info>>> result = {
1234 = {
abss = [(account = 1234, opportunity = abss, value = 10, desc = vip)],
abs = [(account = 1234, opportunity = abs, value = 5, desc = testing),
(account = 1234, opportunity = abs, value = 4, desc = test)]
},
123 = {
abss = [(account = 123, opportunity = abss, value = 8, desc = vip)]
},
12 = {
absddd = [(account = 12, opportunity = absddd, value = 4, desc = production)],
absooo = [(account = 12, opportunity = absooo, value = 2, desc = test)]
}
}
o/p 根据值排序(10->(5+4)->8->4->2)
到目前为止我已经尝试过=infos.stream().collect(Collectors.groupingBy(Info::getAccount, Collectors.groupingBy(r -> r.getOpportunity(), Collectors.toList())))
但它是随机排序的。