Reputation: 320
I have a TreeMap which maps a key to an ArrayList. I would like access each of the elements stored inside each ArrayList of the TreeMap.
Is there a method to do this?
The elements of the ArrayList are of type String.
Upvotes: 0
Views: 98
Reputation: 6463
I understand that you want to loop over all the elements in your TreeMap lists. You can achieve this easily with Java 8 streams:
treeMap.values().stream().flatMap(List::stream).forEach(element -> doStuff(element));
For more information, please refer to:
http://www.oracle.com/technetwork/articles/java/ma14-java-se-8-streams-2177646.html
Upvotes: 1