Posts Tagged ‘iterator’
Accessing the Map values using keySet iterator
A common mistake is to retrieve values from a Map while iterating over the Map keys with keySet()
. Calling Map.get(key)
for each entry is expensive and should be avoided for better performance.
Use entrySet()
iterator to avoid the Map.get(key)
lookup.