4
轉化的模式列表進入地圖與地圖內我有一個List<Model>
:使用Java 8流
[
{parent: "parent", child: "child1", sensor: "wohoo"},
{parent: "parent", child: "child1", sensor: "bla"},
{parent: "parent", child: "child2", sensor: "wohoo2"}
]
,我想將其轉換爲地圖<String, Map<String, List<String>>>
。
{
parent: {
child1: ["wohoo", "bla"],
child2: ["wohoo2"]
},
}
我已經試過這樣:
Map<String, Map<String, List<String>>> test = currentlyReportingAgents
.stream()
.collect(Collectors.groupingBy(
Model::getParent,
Collectors.groupingBy(Model::getChild, Collectors.toList())));
但有一些有線編譯錯誤..我在想什麼?
請在您的問題編譯錯誤。 – khelwood