map遍历的4种方式
来源:互联网 发布:知乎live可以事后看吗 编辑:程序博客网 时间:2024/05/21 18:02
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"); //第1种:普遍使用,二次取值 System.out.println("通过Map.keySet遍历key和value:"); for (String key : map.keySet()) { System.out.println("key= "+ key + " and value= " + map.get(key)); } //第2种:通过迭代器 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()); } //第3种:推荐,尤其是容量大时 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()); } //第4种:只能取出值 System.out.println("通过Map.values()遍历所有的value,但不能遍历key"); for (String v : map.values()) { System.out.println("value= " + v); } }
1 0
- Map集合的4种遍历方式
- Map的4种遍历方式
- map遍历的4种方式
- Map的4种遍历方式
- 遍历map的4种方式
- map的4种遍历方式
- map的四种遍历方式,map遍历元素
- Map的遍历方式
- Map的遍历方式
- 遍历Map的方式
- map的遍历方式
- Map的遍历方式
- 遍历Map的方式
- Map的遍历方式
- Map的遍历方式
- map遍历的方式
- 遍历map的方式
- map的遍历方式
- 使用gitpage和hexo开发你自己的博客更新
- github 官网 ionic-datapicker 插件用法
- 从零开始学习音视频编程技术(八) FFMPEG Qt视频播放器之音视频同步
- hibernate 注释 唯一键约束 uniqueConstraints
- 使用线程池和反射实现异步任务
- map遍历的4种方式
- 1
- 写一个函数,求一个字符串的长度。
- fmt:formatDate格式化日期 各种类型 to Date
- 汤姆大叔深入理解JavaScript系列
- [Spring boot]配置文件properties加载
- Fresco图片框架初始化介绍
- 如何解决XML文件中的警告提示“No grammar constraints (DTD or XML Schema) referenced in the document.” .
- 浅析Java中的final关键字