简体   繁体   English

如何转换列表<map<string, string> &gt; 列出<map<string, map<string, string> &gt;&gt; </map<string,></map<string,>

[英]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.

相关问题 如何转换地图 <String, List<String> &gt;到地图 <String, String> 在java 8中 - How to Convert a Map<String, List<String>> to Map<String, String> in java 8 如何转换列表<map<string, object> > 列出<map<string, string> > </map<string,></map<string,> - How to Convert List<Map<String, Object>> to List<Map<String, String>> 将字符串转换为 Map 列表 - Convert String to List of Map 如何转换列表<map<string,object> > 至 Map<string, string> ? </string,></map<string,object> - How to convert List<Map<String,Object>> to Map<String, String>? 如何将java对象列表转换为Map <String, Map<String, String> &gt; - How to convert a list of java objects to Map<String, Map<String, String>> 将字符串转换为列表<map<string, string> &gt;&gt; 用于测试</map<string,> - Convert String to List<Map<String, String>>> for tests Java转换列表 <String> 到地图 <String, String> - Java Convert List<String> to Map<String, String> 转换列表<String>到地图<String, String>在 Java 中 - Convert List<String> to Map<String, String> in Java 转换地图<String, String>到地图<String, List<String> &gt; 分组后 - Convert Map<String, String> to Map<String, List<String>> after GroupingBy 将 map 字符串转换为 map 字符串列表字符串 - Java 7 - convert map string string to map string list string - Java 7
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM