+ Start a Discussion
patskepatske 

Understanding Sets

Hi All,

I've been looking at the "set methods" in the apex lnaguage reference and see that there is no 'get' method for sets.
How does someone iterate through a set of values?

For example I have a Map of type Map<String, List<String>> myMap;

for each of the keys I'd like to do something with the list of values in the map.... to find the list of keys I use the Map Method "keySet()"

so I have a Set<String> s = myMap.keySet();

then I want a loop to iterate through this set and get the list from the map based on the set.value .....

help please???
Best Answer chosen by Admin (Salesforce Developers) 
BoxBox

i guess you're trying to do the following:

Code:
for(String strKey : myMap.keySet())
{
    List<String> thisList = myMap.get(strKey);

    for(integer i = 0; i < thisList.size(); i++)
    {
        // My Processing
    }
}

 


All Answers

BoxBox

i guess you're trying to do the following:

Code:
for(String strKey : myMap.keySet())
{
    List<String> thisList = myMap.get(strKey);

    for(integer i = 0; i < thisList.size(); i++)
    {
        // My Processing
    }
}

 


This was selected as the best answer
patskepatske
Exactly what I was looking for thank you :)
BoxBox
No problem