去除map中键为偶数的元素
来源:互联网 发布:什么是微信公众号矩阵 编辑:程序博客网 时间:2024/05/10 03:11
import java.util.HashMap;import java.util.Iterator;import java.util.Map;public class TestMap {public static void main(String[] args) {HashMap<Integer,String> hm=new HashMap<Integer,String>();hm.put(1, "星期一");hm.put(2, "星期二");hm.put(3, "星期三");hm.put(4, "星期四");hm.put(5, "星期五");hm.put(6, "星期六");hm.put(7, "星期七");/*下面注释的方法会报错,报错原因以后详细分析*//*for(Map.Entry<Integer, String> entry:hm.entrySet()){Integer temp=entry.getKey();if(temp%2==0){hm.remove(1);}}*/Iterator<Map.Entry<Integer, String>> it = hm.entrySet().iterator();while(it.hasNext()){Map.Entry<Integer, String> entry = it.next(); Integer key = entry.getKey(); if(key%2==0){ it.remove(); }}for(Map.Entry<Integer, String> entry:hm.entrySet()){System.out.println(entry.getKey());}}}运行结果
1
3
5
7
阅读全文
0 0
- 去除map中键为偶数的元素
- Ex6_4将字符串中下标值为偶数的元素由小到大排序,其他元素不变
- 将数组中元素排列为奇数在前偶数在后
- map中元素的插入
- Python 去除列表中重复的元素
- Python 去除列表中重复的元素
- Java去除List中重复的元素
- STL-去除list中重复的元素
- 去除列表中不重复的元素
- 去除数组中重复的元素
- 去除数组中重复的元素
- java去除List中重复的元素
- Java去除List中重复的元素
- 去除数组中重复的元素
- Python 去除list中重复的元素
- 去除list中重复的元素
- java去除List中重复的元素
- NSArray中去除重复的元素
- 初尝大数据
- JavaWeb实现文件上传下载功能实例解析
- public/private/protected的具体区别
- Manacher算法
- 条款10:令operator=返回一个refereglce to this
- 去除map中键为偶数的元素
- 钓鱼
- 解决nginx: [error] open() "/usr/local/var/run/nginx.pid" failed错误
- poj Six Degrees of Cowvin Bacon
- js闭包
- 条款11:在operator=中处理“自我赋值
- Oracle PL/SQL开发基础(第二十八弹:使用锁定)
- #1 应用和实例
- 数据结构的重要概念总结