Pier Luigi :
I've a List of Map like this:
List<Map<String,Object>> l = new ArrayList<>();
Map<String,Integer> m = new HashMap<>();
m.put("X", 1);
m.put("Y", 9);
l.add(m);
m = new HashMap<>();
m.put("X", 23);
m.put("Y", 6);
l.add(m);
What is the best method to linearize all map values with lambda primitives to obtain a list like this
List<Integer> = [1, 9, 23, 6]
?
xingbin :
Try:
List<Integer> result = l
.stream()
.flatMap(map -> map.values().stream())
.collect(Collectors.toList());
System.out.println(result); // [1, 9, 23, 6]