java Hashmap Map TreeMap 的几种遍历方式,全网最全,全网最强

package Collec2;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set; public class Test1 { public static void main(String[] args) {
HashMap<Student, String> hashmap_88 = new HashMap<Student, String>();
hashmap_88.put(new Student("张三", 23), "北京");
hashmap_88.put(new Student("李四", 24), "南京");
HashMap<Student, String> hashmap_99 = new HashMap<Student, String>();
hashmap_99.put(new Student("王五", 23), "上海");
hashmap_99.put(new Student("赵六", 24), "深圳");
HashMap<HashMap<Student, String>, String> hm = new HashMap<HashMap<Student, String>, String>();
hm.put(hashmap_88, "第88期基础班");
hm.put(hashmap_99, "第99期基础班"); System.out.println("遍历方式一");
Set<HashMap<Student, String>> ks = hm.keySet();
Iterator<HashMap<Student, String>> it1 = ks.iterator();
while(it1.hasNext()) {
HashMap<Student,String> next_stu_value = it1.next();
Set<Student> stu_set = next_stu_value.keySet();
Iterator<Student> stu_it = stu_set.iterator();
System.out.println(hm.get(next_stu_value)+"有以下学生");
while(stu_it.hasNext()) {
Student student = stu_it.next();
System.out.println("个人信息"+student);
}
} System.out.println("遍历方式二");
for (HashMap<Student, String> hashMap : hm.keySet()) {
System.out.println(hm.get(hashMap)+"有以下学生");
for (Student stu : hashMap.keySet()) {
System.out.println("个人信息"+stu);
}
}
System.out.println("遍历方式三");
Set<HashMap<Student,String>> x=hm.keySet();
for(Iterator<HashMap<Student,String>> it= x.iterator();it.hasNext();) {
HashMap<Student, String> stu_map_value = it.next();
System.out.println(hm.get(stu_map_value)+"有以下学生");
for( Iterator<Student> it2 = stu_map_value.keySet().iterator();it2.hasNext();) {
Student student = it2.next();
System.out.println("个人信息"+student);
}
}
System.out.println("遍历方式四");
Set<Entry<HashMap<Student,String>,String>> entrySet = hm.entrySet();
Iterator<Entry<HashMap<Student, String>, String>> itentry = entrySet.iterator();
while(itentry.hasNext()) {
Entry<HashMap<Student, String>, String> entry = itentry.next();
HashMap<Student,String> map = entry.getKey();
System.out.println(entry.getValue()+"有以下学生");
Iterator<Entry<Student, String>> iterator = map.entrySet().iterator();
while(iterator.hasNext()) {
Entry<Student, String> next = iterator.next();
System.out.println("个人信息"+next.getKey()+" "+next.getValue());
}
}
System.out.println("遍历方式五");
for (Map.Entry<HashMap<Student, String>, String> entry : hm.entrySet()) {
System.out.println(entry.getValue()+"有以下学生");
for (Map.Entry<Student,String> stu : entry.getKey().entrySet()) {
System.out.println("个人信息"+stu.getKey()+" "+stu.getValue());
}
}
System.out.println("遍历方式六");
hm.forEach((K,V)->{
System.out.println(V+"有以下学生");
K.forEach((sub_K,sub_V)->{
System.out.println("个人信息"+sub_K+" "+sub_V);
});
}); Iterator<HashMap<Student, String>> ite2 = hm.keySet().iterator();
while(ite2.hasNext()) {
HashMap<Student,String> next = ite2.next();
Iterator<Entry<Student, String>> iterator = next.entrySet().iterator();
while(iterator.hasNext()) {
Entry<Student, String> entry = iterator.next();
if(entry.getValue().equals("深圳")) {
iterator.remove();
}
}
}
System.out.println("-=-----------------------");
hm.forEach((K,V)->{
System.out.println(V+"有以下学生");
K.forEach((sub_K,sub_V)->{
System.out.println("个人信息"+sub_K+" "+sub_V);
});
}); }
}

最新文章

  1. java中cookie存取值
  2. iOS开发之引用百度地图SDK(一)-----------SDK开发指南
  3. 模拟器的tableView的分割线不显示
  4. 遍历map的四方方法
  5. LWP::UserAgent介绍2
  6. python读取CSV文件
  7. [知了堂学习笔记]_纯JS制作《飞机大战》游戏_第2讲(对象的实现及全局变量的定义)
  8. SQL Server 数据库引擎怎样记录完整备份后修改过的数据
  9. BAT齐聚阿里安全-ASRC生态大会:呼吁联合共建网络安全白色产业链
  10. git remote
  11. spring boot错误: 找不到或无法加载主类
  12. SSM框架的sql中参数注入(#和$的区别)
  13. MYSQL基本操作(下)
  14. Feature Extractor[content]
  15. centos7_ linux : Nginx安装手册
  16. [C语言]进阶|链表
  17. 错误/异常:java.io.FileNotFoundException: .\src\db.properties (系统找不到指定的路径。);的解决方法
  18. 排错-SP2-1503:无法初始化Oracle调用界面解决
  19. html5 canvas在线文本第二步设置(字体边框)等我全部写完,我会写在页面底部
  20. 如何将Excel导入到Mysql数据库中

热门文章

  1. vue项目空格报错,缩进不对报错,格式报错!!!
  2. 关于AttributeError: &#39;NoneType&#39; object has no attribute &#39;send_keys&#39;
  3. acwing 851. spfa求最短路 模板
  4. docker jenkins安装
  5. linux-在指定路径下查询文件夹是否存在
  6. 如何完成述职报告或年终总结PPT
  7. QLineEdit限制数据类型——只能输入浮点型数
  8. C++ 面向对象程序设计复习大纲
  9. (五十九)c#Winform自定义控件-池子(工业)-HZHControls
  10. Python笔记:设计模式之状态模式