entrySet方法比keySet方法效率高
public static void main(String[] args) {
Map<String, String> map = new HashMap<String, String>();
map.put("key1", "key1");
map.put("key2", "key2");
map.put("key3", "key3");
//keySet
Set<String> a = map.keySet();
Iterator<String> it = a.iterator();
while (it.hasNext()) {
String next = it.next();
String val = map.get(next);
System.out.println(val);
}
//entrySet
for (Entry<String, String> item : map.entrySet()) {
String key = item.getKey();
String value = item.getValue();
System.out.println("key:" + key + "→value:" + value);
}
}