遍历HashMap的最佳方式

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 }

 

posted @ 2016-04-10 15:37  TwoFish  阅读(266)  评论(0编辑  收藏  举报