[英]how to convert List<Map<String, String>> to List<Map<String, Map<String, String>>>
Can some on tell me how to convert List<Map<String, String>>
to List<Map<String, Map<String, String>>>
, the key in converted map object of list is one of the value in the map of list.有人能告诉我如何将
List<Map<String, String>>
转换为List<Map<String, Map<String, String>>>
,转换后的 map object 中的键是 Z1D78DC8ED51214E5018B5114FE 的 Z1D78DC8ED51214E5018B5114FE 中的值之一列表。
in short am trying to achieve below.简而言之,我试图实现以下目标。 but I am getting null values in list.
但我在列表中得到 null 值。
List<Object> finalStatus = status.stream().map(map->new HashMap<>().put(map.get("testcase_mapping_run_id"), map)).collect(Collectors.toList()); ```
The problem is the map(map->new HashMap<>().put(map.get("testcase_mapping_run_id"), map))
.问题是
map(map->new HashMap<>().put(map.get("testcase_mapping_run_id"), map))
。 That lambda does not return the newly created map. lambda 不会返回新创建的 map。 It returns whatever
put
returns, which is the previous value of the key in the map .它返回
put
返回的任何内容, 即 map 中键的先前值。 Since the map was empty, the map
always returns null
.由于 map 为空,因此
map
始终返回null
。
So what you want is probably所以你想要的可能是
List<Map<String, Map<String, String>>> = status.stream()
.map(map->{
Map<String, Map<String, String>> newMap = new HashMap<>();
newMap.put(map.get("testcase_mapping_run_id"), map);
return newMap;
})
.collect(Collectors.toList());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.