I have a HashMap<Foo, ArrayList<Bar>> map
with the following structure:
|-- a
| |-- a1
| |-- a2
| `-- a3
|
`-- b
|-- b1
|-- b2
`-- b3
where a
and b
are objects of the type Foo
and a1
, a2
, etc. objects of the type Bar
.
What I want to have is a List<Bar>
with the following structure:
|-- a1
|-- a2
|-- a3
|-- b1
|-- b2
`-- b3
Right now I have this code:
ArrayList<Bar> tempList = new ArrayList<>();
map.values().forEach(tempList::addAll);
return tempList;
But this feels a bit clumsy and inelegant.
How can I achieve this using the standard Java API, preferably with java.util.Stream
(or lambda expressions)?