map转list

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/wonder_dog/article/details/81784159

map转list

转为string类型的list 即key value相加
使用jdk8的新特性流操作
map.entryset().stream().map(et->et.getKey() + “_” + et.getValue()).Colect(tocolect());

转为List<Map<String, object>>

 List<Map<String, Object>> res = new ArrayList<Map<String, Object>>();
        Iterator<Map.Entry<String, List<Commercial>>> entries = merchantMap.entrySet().iterator();
        Map<String, Object> map = null;
        while (entries.hasNext()) {
            Map.Entry<String, List<Commercial>> entry = entries.next();
            
            map = new HashMap();
            map.put("first", entry.getKey());
            map.put("list", entry.getValue());
            res.add(map);
        }

新建另一个map
新建另一个list
先便利取得map

获得map的key放到新建map里 保存到一个key中
然后把value放到另一个key中

把新建的map加入到集合中

猜你喜欢

转载自blog.csdn.net/wonder_dog/article/details/81784159