【发布时间】:2017-02-15 19:03:41
【问题描述】:
所以我有一个键值对的 HashMap,并希望创建一个使用每个键值对实例化的新对象列表。例如:
//HashMap of coordinates with the key being x and value being y
Map<Integer, Integer> coordinates = new HashMap<Integer, Integer>();
coordinates.put(1,2);
coordinates.put(3,4);
List<Point> points = new ArrayList<Point>();
//Add points to the list of points instantiated using key-value pairs in HashMap
for(Integer i : coordinates.keySet()){
points.add(new Point(i , coordinates.get(i)));
}
我如何使用 Java 8 流来做同样的事情。
【问题讨论】:
标签: java java-8 java-stream