Map迭代方式比较
Bug: XXX makes inefficient use of keySet iterator instead of entrySet iterator
Pattern id: WMI_WRONG_MAP_ITERATOR, type: WMI, category: PERFORMANCE
This method accesses the value of a Map entry, using a key that was retrieved from a keySet iterator. It is more efficient to use an iterator on the entrySet of the map, to avoid the Map.get(key) lookup.
for (String key : map.keySet()) {
System.out.println("key = " + key + ", value = " + map.get(key));
}
此处findbugs提示的是效率高低问题
我们应该尽量使用以下方式进行map的遍历
for (Entry<?,?> entry: map.entrySet()) {
System.out.println("key = " +entry.getKey() + ", value = " + entry.getValue());
}