Tag Archives: List

Get All List Values From A Map To A Single List

Sample Code:

//Map with Country Key and City values
Map<String, List<String>> objMap = new Map<String, List<String>>();

List<String> usaCityList = new List<String>{'New York', 'Los Angeles', 'Chicago', 'San Diego'};
objMap.put('USA', usaCityList);

List<String> indiaCityList = new List<String>{'New Delhi', 'Mumbai', 'Chennai', 'Bangalore'};
objMap.put('India', indiaCityList);

//Get All cities in a single list variable
List<String> objCityList = new List<String>();
for (List<String> obj : objMap.values()){
    objCityList.addAll(obj);
}
System.debug('objCityList-' + objCityList);