我有一个List<Model>
:
[
{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())));
但是我遇到了一些奇怪的编译错误...我漏掉了什么吗?
编辑:添加了一个错误截图:
![enter image description here](https://istack.dev59.com/jUdvJ.webp)