-
Java 遍历Map时 删除元素
- package net.nie.test;
-
- import java.util.HashMap;
- import java.util.Iterator;
- import java.util.Map;
-
- public class HashMapTest {
- private static Map<Integer, String> map=new HashMap<Integer,String>();
-
-
-
-
-
-
-
- public static void main(String[] args) {
- map.put(1,"one");
- map.put(2,"two");
- map.put(3,"three");
- map.put(4,"four");
- map.put(5,"five");
- map.put(6,"six");
- map.put(7,"seven");
- map.put(8,"eight");
- map.put(5,"five");
- map.put(9,"nine");
- map.put(10,"ten");
- Iterator<Map.Entry<Integer, String>> it = map.entrySet().iterator();
- while(it.hasNext()){
- Map.Entry<Integer, String> entry=it.next();
- int key=entry.getKey();
- if(key%2==1){
- System.out.println("delete this: "+key+" = "+key);
-
-
- it.remove();
- }
- }
-
- 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);
- }
- }
- }
-
相关阅读:
解决execjs 调用js 问题
处理 get请求套字典问题
js2py js逆向
前端页面自适应
newspaper抓新闻
easygui
pycharm 安装插件
scrapy_代理使用
SQLAlchemy 介绍,建表,及表的操作 (增 删 改 查)
数据分析之pandas模块下
-
原文地址:https://www.cnblogs.com/dingchenghong/p/2468467.html
Copyright © 2020-2023
润新知