//7种遍历hashMap的方法
public class HashMapCurrent {public static void main(String[] args) {HashMap<Integer,String> hashMap = new HashMap<>();hashMap.put(1,"xiaoming");hashMap.put(2,"xiaobai");hashMap.put(3,"xiaohong");//迭代器遍历  entrySetfinal Iterator<Map.Entry<Integer, String>> iterator = hashMap.entrySet().iterator();while (iterator.hasNext()){final Map.Entry<Integer, String> next = iterator.next();System.out.println(next.getKey());System.out.println(next.getValue());}    // 迭代器遍历  keySetfinal Iterator<Integer> iterator1 =hashMap.keySet().iterator();while (iterator1.hasNext()){final Integer next = iterator1.next();System.out.println(next);System.out.println(hashMap.get(next));} //for循环便利 entrySetfor(Map.Entry<Integer,String> entry:hashMap.entrySet()){System.out.println(entry.getKey());System.out.println(entry.getValue());} //for循环便利keySetfor(Integer key:hashMap.keySet()){System.out.print(key);System.out.print(hashMap.get(key));}//lambda表达式遍历hashMap.forEach((key,value)->{System.out.println(key);System.out.println(value);}); //Stream流遍历  单线程hashMap.entrySet().stream().forEach((entry)->{System.out.println(entry.getValue());System.out.println(entry.getKey());});//Stream流遍历  多线程hashMap.entrySet().parallelStream().forEach((entry)->{System.out.println(entry.getKey());System.out.println(entry.getValue());});}
}

七种遍历HashMap的方法相关推荐

  1. java五种遍历HashMap的方法和性能分析

    在本文中,我们将通过示例讨论在 Java 上遍历 HashMap 的五种最佳方法. 使用Iterator迭代 使用 For-each + entrySet 循环遍历 HashMap 使用 For-ea ...

  2. java中遍历HashMap的方法

    Java中,通常有两种遍历HashMap的方法,如下: import java.util.*; public class MapTest { static HashMap<String, Int ...

  3. 笔记本网络计算机和设备不可见,xp电脑不显示无线网络的七种原因和解决方法...

    xp纯净版系统电脑打开后发现桌面右下角不显示无线网络,如果要设置无线网络都不知道从哪里下手,这到底是怎么回事?造成xp系统不显示无线网络的原因有很多种,下面和大家讲解一下xp电脑不显示无线网络的七种原 ...

  4. java 遍历hashmap key_Java5种遍历HashMap数据的写法

    本文介绍了最好的Java5种遍历HashMap数据的写法,分享给大家,也给自己留一个笔记,具体如下: 通过EntrySet的迭代器遍历 Iterator < Entry < Integer ...

  5. java中高效遍历list_Java中四种遍历List的方法总结(推荐)

    实例如下: package com.ietree.basic.collection.loop; import java.util.ArrayList; import java.util.Iterato ...

  6. java遍历list_Java中四种遍历List的方法总结(推荐)

    实例如下: package com.ietree.basic.collection.loop; import java.util.ArrayList; import java.util.Iterato ...

  7. C#Winform的DataGridView控件使用详解1—七种DataGridViewColumn类型使用方法

    C#Winform的DataGridView控件使用详解1-七种DataGridViewColumn类型使用方法 DataGirdView控件Column类型 DataGridViewButtonCo ...

  8. 遍历HashMap的方法

    思路 1.首先创建HashMap对象 2.通过使用HashMap对象添加值 public class Test {public static void main(String[] args) {Has ...

  9. python实现二叉树和它的七种遍历

    介绍: 树是数据结构中非常重要的一种,主要的用途是用来提高查找效率,对于要重复查找的情况效果更佳,如二叉排序树.FP-树.另外可以用来提高编码效率,如哈弗曼树.  代码: 用python实现树的构造和 ...

最新文章

  1. html中有csstext方法吗,style对象的cssText方法有哪些使用方法
  2. EXT3与EXT4的主要区别
  3. android-cmake环境变量
  4. TeeChart用法(网络收集)默认分类 2010-03-05 21:46:05 阅读788 评论0 字号:大中小 .
  5. DATAGUARD 三种保护模式
  6. mysql添加普通用户用于管理单一数据库
  7. P1407-[国家集训队]稳定婚姻【tarjan,强连通分量】
  8. pytorch深度学习_深度学习和PyTorch的推荐系统实施
  9. 如何做优化,UITabelView才能更加顺滑
  10. 微型计算机中常体积的,微型计算机原理及应用第2章.ppt
  11. IBM Mainframe 基础知识学习 (EBCDIC,dsp3270)
  12. cas-client配置
  13. 拓端tecdat|R语言生存分析可视化分析
  14. 光伏发电最大功率点(MPPT)跟踪技术
  15. 基于.net开发chrome核心浏览器【六】
  16. 水木周平戏说中国网络黑幽默
  17. 分别用Java应用程序和Applet程序实现星星三角形图案的绘制
  18. 监督学习之分类学习:支持向量机
  19. Android字符串格式化
  20. 四棱锥和三棱锥重叠求面数

热门文章

  1. 数据库主键和外键的作用?
  2. sublime安装和使用教程
  3. JAVA生成图片缩略图、JAVA截取图片局部内容
  4. 买WIFI的iPad2好还是3G的好?
  5. spring 标签注入
  6. Access教程 第六章 数据库实例分析
  7. 多弹协同攻击时的无源定位(一)
  8. StateMachineBehaviours动画控制脚本
  9. 以太坊可用RPC节点列表
  10. python序列的主要特点_python的序列类型及其特点-女性时尚流行美容健康娱乐mv-ida网...