七种遍历HashMap的方法
//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的方法相关推荐
- java五种遍历HashMap的方法和性能分析
在本文中,我们将通过示例讨论在 Java 上遍历 HashMap 的五种最佳方法. 使用Iterator迭代 使用 For-each + entrySet 循环遍历 HashMap 使用 For-ea ...
- java中遍历HashMap的方法
Java中,通常有两种遍历HashMap的方法,如下: import java.util.*; public class MapTest { static HashMap<String, Int ...
- 笔记本网络计算机和设备不可见,xp电脑不显示无线网络的七种原因和解决方法...
xp纯净版系统电脑打开后发现桌面右下角不显示无线网络,如果要设置无线网络都不知道从哪里下手,这到底是怎么回事?造成xp系统不显示无线网络的原因有很多种,下面和大家讲解一下xp电脑不显示无线网络的七种原 ...
- java 遍历hashmap key_Java5种遍历HashMap数据的写法
本文介绍了最好的Java5种遍历HashMap数据的写法,分享给大家,也给自己留一个笔记,具体如下: 通过EntrySet的迭代器遍历 Iterator < Entry < Integer ...
- java中高效遍历list_Java中四种遍历List的方法总结(推荐)
实例如下: package com.ietree.basic.collection.loop; import java.util.ArrayList; import java.util.Iterato ...
- java遍历list_Java中四种遍历List的方法总结(推荐)
实例如下: package com.ietree.basic.collection.loop; import java.util.ArrayList; import java.util.Iterato ...
- C#Winform的DataGridView控件使用详解1—七种DataGridViewColumn类型使用方法
C#Winform的DataGridView控件使用详解1-七种DataGridViewColumn类型使用方法 DataGirdView控件Column类型 DataGridViewButtonCo ...
- 遍历HashMap的方法
思路 1.首先创建HashMap对象 2.通过使用HashMap对象添加值 public class Test {public static void main(String[] args) {Has ...
- python实现二叉树和它的七种遍历
介绍: 树是数据结构中非常重要的一种,主要的用途是用来提高查找效率,对于要重复查找的情况效果更佳,如二叉排序树.FP-树.另外可以用来提高编码效率,如哈弗曼树. 代码: 用python实现树的构造和 ...
最新文章
- html中有csstext方法吗,style对象的cssText方法有哪些使用方法
- EXT3与EXT4的主要区别
- android-cmake环境变量
- TeeChart用法(网络收集)默认分类 2010-03-05 21:46:05 阅读788 评论0 字号:大中小 .
- DATAGUARD 三种保护模式
- mysql添加普通用户用于管理单一数据库
- P1407-[国家集训队]稳定婚姻【tarjan,强连通分量】
- pytorch深度学习_深度学习和PyTorch的推荐系统实施
- 如何做优化,UITabelView才能更加顺滑
- 微型计算机中常体积的,微型计算机原理及应用第2章.ppt
- IBM Mainframe 基础知识学习 (EBCDIC,dsp3270)
- cas-client配置
- 拓端tecdat|R语言生存分析可视化分析
- 光伏发电最大功率点(MPPT)跟踪技术
- 基于.net开发chrome核心浏览器【六】
- 水木周平戏说中国网络黑幽默
- 分别用Java应用程序和Applet程序实现星星三角形图案的绘制
- 监督学习之分类学习:支持向量机
- Android字符串格式化
- 四棱锥和三棱锥重叠求面数