我是靠谱客的博主 威武大雁,这篇文章主要介绍Map迭代器遍历过程中,remove报错问题,现在分享给大家,希望可以做个参考。

Map<String, Integer> myHashMap = new IdentityHashMap<>();//IdentityHashMap类型可以put相同key
		myHashMap.put("1", 1);
		myHashMap.put("21", 21);
		myHashMap.put("31", 41);
		myHashMap.put("51", 51);
		Iterator<Map.Entry<String, Integer>> entries = myHashMap.entrySet().iterator();
		while (entries.hasNext()) {
			Map.Entry<String, Integer> entry = entries.next();
			System.out.println("遍历的结果" + entry.getKey() + ":" + entry.getValue());
			//移除map中value值为1的键值对
			if (entry.getValue() == 1) {
				System.out.println("22222222222");
				entries.remove();
			}
		}
		//打印移除后的map内容
		for (Map.Entry<String, Integer> entry1 : myHashMap.entrySet()) {
			System.out.println("key:" + entry1.getKey() + " value:" + entry1.getValue());

		}
	}

最后

以上就是威武大雁最近收集整理的关于Map迭代器遍历过程中,remove报错问题的全部内容,更多相关Map迭代器遍历过程中内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(128)

评论列表共有 0 条评论

立即
投稿
返回
顶部