[SalesForce] Get all List values from a map

I have a map of List for custom wrapper object records as below

Map<String, List<Custom wrapper object>>

I want to get all the records in one list together irrespective of the key of map.

How can this be achieved?

Best Answer

It's a pretty simple structure to flatten.

List<MyWrapper> flattened = new List<MyWrapper>();
for (List<MyWrapper> collection : myMap.values())
    flattened.addAll(collection);
Related Topic