Basically enhanced for loop works with all the collection which are iterable.
so in our case if we take LinkedHashMap , it is not iterable directly because
1)its not a collection , its a key value pair.
2)we cant iterate to get key value directly.
so we need to take keys and put them into some collection, say set.
why set? because map will have unique(no duplicate) keys so they implemented a method
inside a map called keySet.
so map.keySet() returns the set of keys.
now we can iterate easily using for loop as set is iterable.
so we have written
for (String s : Pairs.keySet())
now each s in the above syntax is a string coming from keySet one by one on every iteration.
Now compare passed name with value for the corresponding key inside a map and if they are equal add that name to the list
Pairs.get(s)
-> gives value of the map for the key s.
if (phoneticName.equals(Pairs.get(s))) {
matchedNames.add(s);
}
at the end of method return this newly formed matched list.