From Map to List
I'm working with a Map, and i'm trying to pass the values of a Map as the elements for the creation of a new list. I have tried various ways so far, but to no avail. I suspect i maybe missing the obvious.
List<someObject> holder = new ArrayList<someObject>();
Instance Variable Declaration;
Map <String, List<someObject> someMap;
Your addAll() expects a List<someObject>.
Your values() is returning a List<List<someObject>>. So they're not compatible.
You'll have to loop round the values() and addAll() each individual List<someObject>.
ETA: Sorry, that should be Collection<List<someObject>>, but the point still stands.
You Map contains String elements as keys as List<someObject> elements as associated values. Do you want to 'flatten' all those lists in one big list? If so, view the Map as an entrySet() and add all the values (those are the lists) to your final list. Or create a values() collection and iterate over it and do the same with each element:
Originally Posted by JC_Drumcondra
for (List<someObject> value : yourMap.values())