List<Map>转为Map<String, List<Map<String, Object>>>
时间: 2023-09-24 12:12:04 浏览: 131
可以通过循环遍历List
以下是示例代码:
List<Map> list = new ArrayList<>(); // 原始的List<Map>
Map<String, List<Map<String, Object>>> resultMap = new HashMap<>(); // 转换后的Map
for (Map<String, Object> map : list) {
for (Map.Entry<String, Object> entry : map.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
if (!resultMap.containsKey(key)) {
resultMap.put(key, new ArrayList<>());
}
Map<String, Object> newMap = new HashMap<>();
newMap.put(key, value);
resultMap.get(key).add(newMap);
}
}
这样就将原始的List
阅读全文
相关推荐
















