Say I have a Map extends Object, List
I can get the values of the map easily enough, and iterate over it to produce a single
No, there is no shorter method. You have to use a loop.
Update Apr 2014: Java 8 has finally come out. In the new version you can use the Iterable.forEach method to walk over a collection without using an explicit loop.
Update Nov 2017: Found this question by chance when looking for a modern solution. Ended up going with reduce
:
someMap.values().stream().reduce(new ArrayList(), (accum, list) -> {
accum.addAll(list);
return accum;
}):
This avoids depending on mutable external state of forEach(someList::addAll)
the overhead of flatMap(List::stream)
.