hashMap 的遍历:
来源:互联网 发布:查看80端口占用情况 编辑:程序博客网 时间:2024/05/24 06:48
遍历的方法有两种:
一、 entrySet:
Map map = new HashMap(); Iterator iter = map.entrySet().iterator(); while (iter.hasNext()) { Map.Entry entry = (Map.Entry) iter.next(); Object key = entry.getKey(); Object val = entry.getValue(); }这种方法可以变化为for循环:
Map<String, String> map = new HashMap<String, String>();for (Entry<String, String> entry : map.entrySet()) { entry.getKey(); entry.getValue();}
二、ketSet
Map map = new HashMap(); Iterator iter = map.keySet().iterator(); while (iter.hasNext()) { Object key = iter.next(); Object val = map.get(key); }这种方法变为for循环:
Map<String, String> map = new HashMap<String, String>();for (String key : map.keySet()) { map.get(key);}
如果只需要Key 的话用第二种方法, key 和 value 都需要的话用第一种方法。
0 0
- HashMap对象的遍历
- HashMap 的遍历
- hashmap的遍历
- Java_ABC_10.HashMap的遍历
- HashMap的遍历键值
- HashMap的遍历
- Hashmap的遍历
- HashMap的遍历方法
- HashMap的遍历
- HashMap HashTable 的遍历
- 遍历HashMap的方法
- android的HashMap遍历
- java HashMap的遍历
- 遍历HashMap的方法
- hashMap的遍历
- hashMap的遍历
- hashmap的遍历方法
- 【java】HashMap的遍历
- 输入一个矩阵,输入初始坐标和目的坐标,输出最短路径(之一)及路径的各个坐标
- 随机采块边界的界定
- 获取前一天时间
- oracle 单引号中含有字符串
- 跟老杨学java系列(二) PNP训练法介绍
- hashMap 的遍历:
- jsp基本语法
- byte、short、char和int的转换
- 用GithubPages建博客
- [Android] Android 判断SD卡是否存在及容量查询
- 运行menge时的一些小操作
- TCP通信流程解析
- 最新CocoaPods安装教程,保证可用
- 多项式加减运算—c语言描述