Java代码
- package,,,,,,,,,,,==){
- System.out.println("delete this: "+key+" = "+key);
- //map.put(key, "奇数"); //ConcurrentModificationException
- //map.remove(key); //ConcurrentModificationException
- it.remove(); //OK
- }
- }
- //遍历当前的map;这种新的for循环无法修改map内容,因为不通过迭代器。
- System.out.println("-------\n\t最终的map的元素遍历:");
- for(Map.Entry<Integer, String> entry:map.entrySet()){
- int k=entry.getKey();
- String v=entry.getValue();
- System.out.println(k+" = "+v);
- }
- }
- }