NavigableMap<String, String> map; // this map contains e.g. 10 elements
MyObject foo = new MyObject("string as 1st parameter", "and as 2nd parameter");
现在我想做这样的事情:
List<MyObject> objects = new ArrayList<>();
objects.addAll(forEach(map) {new MyObject(map.key, map.value)});
我知道,我可以遍历地图:
for (String key : map.keySet()) {
objects.add(new MyObject(key, map.get(key)));
}
我的问题是,这是否可能以其他更加时髦的方式:)(在JAVA 7内)