遍历Map
来源:互联网 发布:u盘安装linux centos7 编辑:程序博客网 时间:2024/06/06 05:14
public static void main(String[] args) { 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()); } // 第三种:推荐,尤其是容量大时 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); } }
出处http://www.cnblogs.com/kristain/articles/2033566.html
0 0
- 遍历MAP
- 遍历Map
- 遍历Map
- map遍历
- Map 遍历
- 遍历map
- 遍历MAP
- Map遍历
- Map 遍历
- MAP遍历
- 遍历Map
- 遍历Map
- 遍历Map
- Map 遍历
- Map遍历。。。。
- Map遍历
- 遍历Map
- map遍历
- Flashback Version Query && Flashback Transaction Query
- LeetCode 106 Permutations II
- 部署SSL证书解决ios7.1的app下载有关问题
- Hibernate与 MyBatis的比较
- 为推广3D应用,目前尤尼科技计划启动一系列3D打印机进校园活动
- 遍历Map
- Python yield 使用浅析
- Web.xml配置详解之context-param
- poj 3613 Cow Relays
- Aspect Oriented Programming with Spring
- listview item设置间距无效与去掉默认黄色的selector
- ios 用了svn管理代码,项目文件越来越大,远超出实际代码文件大小
- cell的常用属性
- linux shell编程中的特殊符号