遍历Map的最佳方法
public static void printMap(Map<Object, Object> mp) {
for (Map.Entry entry : mp.entrySet()) {
System.out.println(entry.getKey() + " = " + entry.getValue());
}
}
public static void printMap(Map mp) {
Map<?, ?> contentsTyped = (Map<?, ?>) params;
for (Map.Entry<?, ?> entry : contentsTyped.entrySet()) {
System.out.println(String.valueOf(entry.getKey()) + " = " + String.valueOf(entry.getValue()));
}
}
public static void printMap(Map mp) {
Iterator it = mp.entrySet().iterator();
while (it.hasNext()) {
Map.Entry pair = (Map.Entry)it.next();
System.out.println(pair.getKey() + " = " + pair.getValue());
it.remove(); // avoids a ConcurrentModificationException
}
}