Issue
I have a Map<String, List<MyObject> myMap
. How can I join all the List values into one List<MyObject>
, excluding the String key?
I tried with this
List<MyObject> list = new ArrayList<MyObject>(myMap.values())
but this does not work with a collection.
Also thought of just iterating over the Maps and joining each list to a new list, but was hoping for a better way.
Solution
here is a possible way with streams
map.values().stream().flatMap(Collection::stream).collect(Collectors.toList())
Answered By - energy2522
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.