package com.heima.test;
import java.util.HashMap;
import com.heima.bean.Student;
public class Test5 {
/**
* 集合嵌套之HashMap嵌套HashMap
*
* 双元课堂有很多基础班 第88期基础班定义成一个双列集合,键是学生对象,值是学生的归属地
* 第99期基础班定义成一个双列集合,键是学生对象,值是学生的归属地
*
* 无论88期还是99期都是班级对象,所以为了便于统一管理,把这些班级对象添加到双元课堂集合中
*/
public static void main(String[] args) {
HashMap<Student, String> hm88 = new HashMap<>();
hm88.put(new Student("张三", 23), "北京");
hm88.put(new Student("张三", 23), "上海");
hm88.put(new Student("李四", 24), "北京");
hm88.put(new Student("王五", 25), "广州");
hm88.put(new Student("张三", 24), "北京");
HashMap<Student, String> hm99 = new HashMap<>();
hm99.put(new Student("唐僧", 23), "北京");
hm99.put(new Student("沙僧", 23), "上海");
hm99.put(new Student("猪八戒", 24), "北京");
hm99.put(new Student("孙悟空", 25), "广州");
hm99.put(new Student("白龙马", 23), "北京");
HashMap<HashMap<Student, String>, String> hm = new HashMap<>();
hm.put(hm88, “涛涛");
hm.put(hm99,”套套");
for (HashMap<Student, String> h : hm.keySet()) {
String v=hm.get(h);
for(Student s : h.keySet()){
String v1=h.get(s);
System.out.println(s+"...."+v1+"...."+v);
}
}
}
}
|
|