7

怎么用Lambda表达式实现List<Map>的映射

 3 years ago
source link: https://www.oschina.net/question/3447476_2322286
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

怎么用Lambda表达式实现List<Map>的映射

Jessica丶 发布于 04/26 13:51
阅读 179
Map<String,Object> m1 = new HashMap<>();
m1.put("key","a");
m1.put("value",1);
Map<String,Object> m2 = new HashMap<>();
m2.put("key","b");
m2.put("value",2);
List<Map<String,Object>> list = new ArrayList<>();
list.add(m1);
list.add(m2);

上面的list值是[{value=1, key=a}, {value=2, key=b}]

我想把这个list转换成[{a=1},{b=2}],这样的一个List<Map<String,String>>集合,这里需要把上面的Map里面的value全部转成String类型,用Lambda该怎么实现


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK