Iterating over a map (Apex)

These methods are available for all maps.

So one way to code it is to use a keySet() method of the Map.
Firstly you will get all Id's (keys) from the map and then will iterate over that set of keys. Based on the key you can then get a corresponding set of emails:

for (Id key : emailDiseaseMap.keySet()) {
    // The "key" variable is also available inside the loop
    List<String> toAddresses = emailDiseaseMap.get(key);
    // ... emailing logic
}

Hi you can iterate over that like as follows-

 for(Id id: mapname.keyset()){
    Set<String> stringset= mapname.get(id);
    for(String a: stringset){
         sendMail(a);
   }

Tags:

Map

Apex