【发布时间】:2019-07-28 16:36:25
【问题描述】:
假设我有一张地图列表
List<Map<String, Double>> maps = new ArrayList<>();
Map<String, Double> map1 = new HashMap();
map1.put("height",60D);
map1.put("weight",144D);
maps.add(map1);
Map<String, Double> map2 = new HashMap();
map2.put("height",63D);
map2.put("weight",192D);
maps.add(map2);
等等……
创建身高或体重列表的最快方法是什么? 诸如列表高度之类的东西。
经典的方法是查看地图,使用 if 条件并搜索高度键,如果找到,则将其添加到返回列表中。
使用流的等效方法是什么?
【问题讨论】:
-
它不应该编译,你有一个
List<HashMap<String, Double>>,但添加Map<String, Double>s
标签: java list dictionary java-8 java-stream