+ Start a Discussion
ImNickImNick 

how to iterate over map of Map<ID,List<String>>

how to iterate over map of Map<ID,List<String>>in apex
Best Answer chosen by ImNick
GauravGargGauravGarg
Hi Nick,

As you are using List inside the Map, that means you need to loop over two variables like below:
Map<Id, list<String>> idToStringMap = new Map<Id, List<String>>();

for(Id idValue : idToStringMap.keyset())
{
   for(String s : idToStringMap.get(idValue ))
    {
        system.debug(' Map keyset Id Value' + idValue );
        system.debug(' list values : '+ s);
     }
}


Let me know if you have more question on it.

Thanks,

Gaurav
skype: gaurav62990

All Answers

GauravGargGauravGarg
Hi Nick,

As you are using List inside the Map, that means you need to loop over two variables like below:
Map<Id, list<String>> idToStringMap = new Map<Id, List<String>>();

for(Id idValue : idToStringMap.keyset())
{
   for(String s : idToStringMap.get(idValue ))
    {
        system.debug(' Map keyset Id Value' + idValue );
        system.debug(' list values : '+ s);
     }
}


Let me know if you have more question on it.

Thanks,

Gaurav
skype: gaurav62990

This was selected as the best answer
ImNickImNick
Map<ID,List<String>> testmap = new Map<ID,List<String>> ();

for (Id id : testmap .keySet())
            {
                System.debug('Key is '+ id);
                System.debug('this prints whole related list '+testmap .get(id));
                for(String s : testmap .get(id))
                {
                    System.debug('this prints list of string with each value separated  '+s);
                }
            }