hashmap遍历中删除键值对

public class test {
    public static void main(String[] args) {
        Map<String, String> maps = new HashMap<String, String>();
        maps.put("10", "AA");
        maps.put("11", "BB");
        maps.put("12", "CC");
        maps.put("13", "DD");


        for (IteratorString, String>> it = maps.entrySet().iterator(); it.hasNext(); ) {
            Map.Entry<String, String> item = it.next();//此句不能少,否则,删除当前节点,指针无法找到下一节点
            String abc = Integer.toHexString(item.hashCode());
            it.remove();
        }
    }
}

你可能感兴趣的:(Java)