我有一个List<Map<String, Object>>
这样的列表
[
{"A": 50,
"B": 100,
"C": 200,
"D": "Auction"
},
{
"A": 101322143.24,
"B": 50243301.2,
"C": 569,
"D": "Sold Promissory Buyer"
},
{
"A": 500,
"B": 1000,
"C": 1500,
"D": "Auction"
}]
我正在使用此流 API 方法将此列表转换为 Map
finalSalesReportForSoldProperty.stream().collect(Collectors.toMap(tags -> ((String) tags.get("D")).replaceAll("[\\- ]", ""), Function.identity()));
但它抛出了我java.lang.IllegalStateException: Duplicate key
的异常,因为我的列表有重复的键
我想添加重复键的内部元素,我想要这样的输出
"Auction": {
"A": 550,
"B": 1100,
"C": 1650,
"D": "Auction"
} ,
"Sold Promissory Buyer" :{
"A": 101322143.24,
"B": 50243301.2,
"C": 569,
"D": "Sold Promissory Buyer"
}
是否可以通过 Java 流 API?