Java遍历Map的四种方法
来源:互联网 发布:contabs.js插件 编辑:程序博客网 时间:2024/05/21 16:00
原文地址: http://www.cnblogs.com/kristain/articles/2033566.html
public static void main(String[] args) { Map<String, String> map = new HashMap<String, String>(); map.put("1", "value1"); map.put("2", "value2"); map.put("3", "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()); } //第三种:推荐,尤其是容量大时 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
- java Map 遍历的四种方法
- java 遍历Map的四种方法
- java遍历Map的四种方法
- java 遍历Map的四种方法
- Java 遍历Map的四种方法
- JAVA 遍历Map的四种方法
- Java遍历Map的四种方法
- java 遍历Map的四种方法
- java遍历Map的四种方法
- Java遍历Map的四种方法
- Java中Map遍历常用的四种方法
- Java中Map遍历常用的四种方法
- Java初学习 - 遍历Map的四种方法
- java 中map遍历的四种方法和优缺点
- java基础--遍历Map的四种方法
- java中遍历map对象的四种方法
- Java中,Map遍历的四种方法
- java中遍历map的四种方法
- hibernate eventes not mapped[HQL] exception
- PKI技术原理
- android 解决两个应用互相跳转,如果应用已经启动还是会重新打开应用的问题
- thinkphp之category tree
- JFlow工作流 流程与表单案例
- Java遍历Map的四种方法
- Linux- 线程函数如何将返回值传给主线程
- selenium2.x python 虚拟浏览器 搭建与使用
- Redhat6.2安装thrift0.9.1
- c# Eval函数中将日期显示的格式修改为yyyy-MM-dd形式
- 信息学奥林匹克竞赛-校门外的树
- cocos2dx-lua方法笔记
- 在Ubuntu中遇到Unable to lock the administration directory (/var/lib/dpkg/),are you root? 问题解决办法
- 关于UniversalImageLoader加载图片时的闪烁问题