0
列表获取条目列表我有以下结构的HashMap<Foo, ArrayList<Bar>> map
:的Java:从嵌套在HashMap中
|-- a
| |-- a1
| |-- a2
| `-- a3
|
`-- b
|-- b1
|-- b2
`-- b3
其中a
和b
是类型Foo
和a1
,a2
等对象中的对象键入Bar
。
我想有一个List<Bar>
结构如下:
|-- a1
|-- a2
|-- a3
|-- b1
|-- b2
`-- b3
现在我有这样的代码:
ArrayList<Bar> tempList = new ArrayList<>();
map.values().forEach(tempList::addAll);
return tempList;
但是,这感觉有点笨拙和不雅。 如何使用标准Java API实现此目标,最好使用java.util.Stream
(或lambda表达式)?
参见http://stackoverflow.com/questions/31056919/concatenate-the-string-values-of-all-maps-in-a-list或http://stackoverflow.com/questions/ 35682522 /转换-mapstring-navigablemaplong-collectionstring到liststring,全光照 – Tunaki