package com.day15.Map;
/*
* HashMap嵌套HashMap
*/
import java.util.HashMap;
import com.day15.bean.Student;
public class HashMap_Two {
public static void main(String[] args) {
//定义1期班
HashMap<Student, String> hm1=new HashMap<>();
hm1.put(new Student("Kobe",20), "LA");
hm1.put(new Student("KG",21), "Boston");
hm1.put(new Student("PP",22), "Boston");
hm1.put(new Student("Allen",23), "Nanjing");
//定义2期班
HashMap<Student, String> hm2=new HashMap<>();
hm2.put(new Student("Zjl",20), "Nanjing");
hm2.put(new Student("XX",21), "Dazhou");
hm2.put(new Student("Zxc",22), "Hongkong");
hm2.put(new Student("Ty",23), "Beijing");
//定义专业
HashMap<HashMap<Student,String>, String> hm=new HashMap<>();
hm.put(hm1, "第一期基础班");
hm.put(hm2, "第二期基础班");
//遍历双列集合
for(HashMap<Student, String> h: hm.keySet()){
String value=hm.get(h);
for(Student key:h.keySet()) {
String value2=h.get(key);
System.out.println(key+"="+value2+key+"="+value);//Student [name=Allen,age=23]=NanjingStudent [name=Allen,age=23]=第一期基础班
//Student [name=Kobe,age=20]=LAStudent [name=Kobe,age=20]=第一期基础班
//Student [name=KG,age=21]=BostonStudent [name=KG,age=21]=第一期基础班
//Student [name=PP,age=22]=BostonStudent [name=PP,age=22]=第一期基础班
//Student [name=Zxc,age=22]=HongkongStudent [name=Zxc,age=22]=第二期基础班
//Student [name=Zjl,age=20]=NanjingStudent [name=Zjl,age=20]=第二期基础班
//Student [name=XX,age=21]=DazhouStudent [name=XX,age=21]=第二期基础班
//Student [name=Ty,age=23]=BeijingStudent [name=Ty,age=23]=第二期基础班
}
}
}
}