hashMap的三种遍历方式
2017-11-27 16:17
204 查看
public void testClass(){ HashMap<String, String> hashMap = new HashMap<String, String>(); hashMap.put("1", "1"); hashMap.put("2", "2"); Set<Entry<String, String>> entrySet = hashMap.entrySet(); Iterator<Entry<String, String>> iterator = entrySet.iterator(); //1.迭代器实现 效率高 while(iterator.hasNext()){ Entry<String, String> entry = iterator.next(); String key = entry.getKey(); System.out.println(key); String value = entry.getValue(); System.out.println(value); } //2.entrySet for (Entry<String, String> entry : entrySet) { System.out.println(entry.getKey() + ":" + entry.getValue()); } //3.keySet Set<String> keySet = hashMap.keySet(); for (String entry : keySet) { System.out.println(hashMap.get(entry)); } }
相关文章推荐
- HashMap的三种遍历方式
- HashMap三种循环遍历方式及其性能对比
- HashMap的三种遍历方式
- HashMap的三种遍历方式
- Java HashMap遍历的三种方式
- HashMap的三种遍历方式
- Java中HashMap遍历的两种方式
- ArrayList三种遍历方式比较
- python中遍历list的三种方式
- HashMap循环遍历方式及其性能对比
- [Java] 遍历HashMap和HashMap转换成List的两种方式
- 初识树结构,简单模拟无规律的二叉树,实现二叉树的构建,计算树的深度以及三种遍历方式以及搜索删除,销毁整个树
- Java中HashMap遍历的两种方式
- List三种遍历方式及效率问题
- 二叉树的常见方法及三种遍历方式 Java 实现
- Java遍历HashMap两种方式
- JAVA Map 的三种遍历方式
- 两种方式遍历HashMap
- HashMap遍历的两种方式,推荐使用entrySet()
- opencv学习(五)之像素遍历三种方式耗时分析