Map 的遍历方法
来源:互联网 发布:java gbk乱码 编辑:程序博客网 时间:2024/06/03 14:20
Map<String, String> map = new HashMap<String, String>(); map.put("key1", "value1"); map.put("key2", "value2"); map.put("key3", "value3"); //第一种:普遍使用,二次取值 System.out.println("通过Map.keySet遍历key和value:"); for (String key : map.keySet()) { System.out.println("key= "+ key + " and value= " + map.get(key)); } //第二种 System.out.println("通过Map.entrySet使用iterator遍历key和value:"); Iterator<Map.Entry<String, String>> it = map.entrySet().iterator(); while (it.hasNext()) { Map.Entry<String, String> entry = it.next(); System.out.println("key= " + entry.getKey() + " and value= " + entry.getValue()); } //第三种:推荐,尤其是容量大时</span> System.out.println("通过Map.entrySet遍历key和value"); for (Map.Entry<String, String> entry : map.entrySet()) { System.out.println("key= " + entry.getKey() + " and value= " + entry.getValue()); } //第四种 System.out.println("通过Map.values()遍历所有的value,但不能遍历key"); for (String v : map.values()) { System.out.println("value= " + v); }
0 0
- Map的遍历方法
- map的遍历方法
- map的遍历方法
- Map的遍历方法
- Map的遍历方法
- Map的遍历方法
- map遍历的方法
- Map的遍历方法
- Map的遍历方法
- 遍历map的方法
- 遍历Map的方法
- Map遍历的方法
- 遍历map的方法
- map的遍历方法
- 遍历map的方法
- map的遍历方法
- Map的遍历方法
- Map的遍历方法
- 移植QT-MYSQL到ARM(客户端版和完整版)
- Activity转场动画
- [Leetcode] 145. Binary Tree Postorder Traversal 解题报告
- 再议字符集和编码
- CodeForces
- Map 的遍历方法
- 微信小程序客服接口
- ARP协议 你不能不知道的
- 喵哈哈村的魔力源泉(4)-(单调队列优化)
- 简单实现上拉下拉,增加头条目和尾条目的RecyclerView
- [UE4]注意事项,插件中蓝图方法库在C++中的使用
- Group by 总结 时光慢点走~~
- 感动哭!Starbreeze发布《收获日2》VR版
- Xcode 找不到头文件