HashMap的四种遍历方式
package com.xt.map; import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set; public class HashMapTest { public static void main(String[] args) { Map<Integer,Student> students=new HashMap<>();
students.put(1, new Student("111")); Set<Integer> Keys=students.keySet();
//
for (Integer key : Keys) {
System.out.println(students.get(key));
}
//
Iterator<Integer> iterator=Keys.iterator();
while(iterator.hasNext()) {
System.out.println(students.get(iterator.next()));
} Set<Entry<Integer,Student>> entrys = students.entrySet();
//
for (Entry<Integer, Student> entry : entrys) {
System.out.println(entry.getValue());
}
//
Iterator<Entry<Integer, Student>> iterator1=entrys.iterator();
while(iterator1.hasNext()) {
System.out.println(iterator1.next().getValue());
}
}
}
HashMap的四种遍历方式的更多相关文章
- Map 的四种遍历方式
Map 的四种遍历方式 import java.util.HashMap; import java.util.Iterator; import java.util.Map; public class ...
- HashMap 中7种遍历方式的性能分析
随着 JDK 1.8 Streams API 的发布,使得 HashMap 拥有了更多的遍历的方式,但应该选择那种遍历方式?反而成了一个问题. 本文先从 HashMap 的遍历方法讲起,然后再从性能. ...
- lua中for循环的四种遍历方式
lua中for的四种遍历方式区别 table.maxn 取最大的整数key #table 从1开始的顺序整数最大值,如1,2,3,6 #table == 3 key,value pairs 取每一 ...
- HashMap的两种遍历方式
HashMap的两种遍历方式 HashMap存储的是键值对:key-value . java将HashMap的键值对作为一个整体对象(java.util.Map.Entry)进行处理,这优化了Hash ...
- list的四种遍历方式
1.手先增强for循环和iterator遍历的效果是一样的,也就说 增强for循环的内部也就是调用iteratoer实现的,但是增强for循环 有些缺点,例如不能在增强循环里动态的删除集合内容.不能获 ...
- HashMap的四种遍历方法,及效率比较(简单明了)
https://yq.aliyun.com/ziliao/210955 public static void main(String[] args) { HashMap<Integer, Str ...
- java集合四种遍历方式
package conection; import java.util.Iterator;import java.util.LinkedList;import java.util.List; publ ...
- HashMap的四种遍历!
HashMap的四种遍历 import java.util.Collection; import java.util.HashMap; import java.util.Map; import jav ...
- HashMap 的 7 种遍历方式与性能分析
前言 随着 JDK 1.8 Streams API 的发布,使得 HashMap 拥有了更多的遍历的方式,但应该选择那种遍历方式?反而成了一个问题. 本文先从 HashMap 的遍历方法讲起,然后再从 ...
随机推荐
- ubuntu如何删除刚添加的源?
答: sudo add-apt-repository -r <source_url> 如: sudo add-apt-repository -r ppa:linaro-maintainer ...
- Jedis的Publish/Subscribe功能的使用
redis内置了发布/订阅功能,可以作为消息机制使用.所以这里主要使用Jedis的Publish/Subscribe功能. 1.使用Spring来配置Jedis连接池 <!-- pool配置 - ...
- mybatisplus
1.selectById 根据主键查询一个对象,如果没有查到,则返回null: GxySchoolDto isExist = gxySchoolMapper.selectById(schoolEnti ...
- JAVA 基础编程练习题12 【程序 12 计算奖金】
12 [程序 12 计算奖金] 题目:企业发放的奖金根据利润提成.利润(I)低于或等于 10 万元时,奖金可提 10%:利润高于 10 万元, 低于 20 万元时,低于 10 万元的部分按 10%提成 ...
- unity2d教程
https://segmentfault.com/a/1190000003965359
- Pearson Correlation Score
[http://www.statisticshowto.com/what-is-the-pearson-correlation-coefficient/] Correlation between se ...
- 说说mysql的存储引擎,有什么区别?索引的介绍
InnoDB 支持ACID事务,支持事务的四种隔离级别,串行化,可重复读,读已提交,读未提交. 支持行级锁以及外检约束:所以可以支持写并发. 不存储总行数. 逐渐索引采用聚集索引,索引的数据域存储数据 ...
- centos7搭建伪分布式集群
centos7搭建伪分布式集群 需要 centos7虚拟机一台: jdk-linux安装包一个 hadoop-2.x安装包1个(推荐2.7.x) 一.设置虚拟机网络为静态IP(最好设成静态,为之后编程 ...
- 【AMAD】django-oauth2-provider -- 为你的app提供Oauth2的访问
简介 个人评分 简介 django-oauth2-provider1主要是为django集成oauth2加入了不少的工具,比如装饰器,Base View, Authentication Backend ...
- Windows Server 2019安装OpenSSH Server简明教程
Windows Server 2019安装OpenSSH Server简明教程 Windows Server 2019内置OpenSSH Server组件了.只不过OpenSSH Server默认 ...