1 public static void printMap(Map mp) { 2 Iterator it = mp.entrySet().iterator(); 3 while (it.hasNext()) { 4 Map.Entry pair = (Map.Entry)it.next(); 5 System.out.println(pair.getKey() + " = " + pair.getValue()); 6 it.remove(); // avoids a ConcurrentModificationException 7 } 8 }
时间: 2024-10-08 15:15:44