Java 8: merge lists with stream API
I think flatMap()
is what you're looking for.
For example:
List<AClass> allTheObjects = map.values()
.stream()
.flatMap(listContainer -> listContainer.lst.stream())
.collect(Collectors.toList());
Alternative: Stream.concat()
Stream.concat(map.values().stream(), listContainer.lst.stream())
.collect(Collectors.toList()
In Java 8 we can use stream List1.stream().collect(Collectors.toList()).addAll(List2); Another option List1.addAll(List2)