FindBugs is complaining of my use of the Map iterators keySet().iterator and get(key).
But I do need the key and the value to work with. Did I take the wrong collection, or did I do something else wrong?
Sample code:
for (final Iterator iter = propertyMap.keySet().iterator(); iter
.hasNext();) {
final String name = (String) iter.next();
final String value = (String) propertyMap.get(name);
//Do something with key and value
}
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Use an entrySet iterator when you need key and value: So do:
for (final Iterator iter = propertyMap.entrySet().iterator(); iter.hasNext();) {
Map.Entry entry = iter.next();
final String name = entry.getKey();
final String value = entry.getValue();
// do something
}
this avoids the map lookup (get) each time thru the loop.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
FindBugs is complaining of my use of the Map iterators keySet().iterator and get(key).
But I do need the key and the value to work with. Did I take the wrong collection, or did I do something else wrong?
Sample code:
for (final Iterator iter = propertyMap.keySet().iterator(); iter
.hasNext();) {
final String name = (String) iter.next();
final String value = (String) propertyMap.get(name);
//Do something with key and value
}
Use an entrySet iterator when you need key and value: So do:
for (final Iterator iter = propertyMap.entrySet().iterator(); iter.hasNext();) {
Map.Entry entry = iter.next();
final String name = entry.getKey();
final String value = entry.getValue();
// do something
}
this avoids the map lookup (get) each time thru the loop.