HashMap은 반복문 돌릴때 어떻게 해요?
조회수 3346회
1 답변
-
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 } }
Iterator 써서 돌리면 돼요!
댓글 입력