package com.heima.homework;
import java.util.HashMap;
import com.heima.work.Student;
public class Test5 {
/**
* 4:集合的嵌套遍历(理解)
*/
public static void main(String[] args) {
HashMap<Student, String> map = new HashMap<>();
map.put(new Student("张三",23), "北京");
map.put(new Student("李四",24), "上海");
map.put(new Student("王五",25), "广州");
map.put(new Student("赵六",26), "深圳");
HashMap<Student, String> map1 = new HashMap<>();
map1.put(new Student("赵四",40),"沈阳");
map1.put(new Student("刘能",50),"长春");
map1.put(new Student("小沈阳",30),"铁岭");
map1.put(new Student("宋小宝",35),"哈尔滨");
HashMap<HashMap<Student, String>,String> hm = new HashMap<>();
hm.put(map, "黑马基础班88期");
hm.put(map1, "黑马基础班99期");
for (HashMap<Student, String> h : hm.keySet()) {
String str = hm.get(h);
for (Student stu : h.keySet()) {
String str2 = h.get(stu);
System.out.println(stu + str2 + str);
}
}
}
}
|
|