遍历map的方法
来源:互联网 发布:mac版炒股软件 编辑:程序博客网 时间:2024/06/05 01:51
//第一种:普遍使用,二次取值
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);
}
}
- Map的遍历方法
- map的遍历方法
- map的遍历方法
- Map的遍历方法
- Map的遍历方法
- Map的遍历方法
- map遍历的方法
- Map的遍历方法
- Map的遍历方法
- 遍历map的方法
- 遍历Map的方法
- Map遍历的方法
- 遍历map的方法
- map的遍历方法
- 遍历map的方法
- map的遍历方法
- Map的遍历方法
- Map的遍历方法
- 蓝桥 算法训练 删除数组零元素
- 拿硬币的必胜方 轮流拿硬币 最后拿的输
- Eclipse 修改字体和皮肤
- iOS 应用程序跳转到appstore
- 符号英文名称
- 遍历map的方法
- Java中文档生成JavaDoc使用注意
- ios:UIAlertView自动消失
- java装饰模式
- Kamailio学习笔记
- 黑马程序员_关于java的转义字符的使用
- Moto XT1085 手机root
- 简历
- Cocos2dx技术(三)——cocos2dx基本概念(五)场景