java:集合框架(集合嵌套之HashMap嵌套HashMap)

版权声明:本文为博主原创文章,未经博主允许不得转载 https://blog.csdn.net/qq_24644517/article/details/83090929
import java.util.HashMap;

import com.heima.bean.Student;

public class Demo8_HashMap {

	public static void main(String[] args) {
		HashMap<Student, String> hs88=new HashMap<>();
		hs88.put(new Student("张三",23),"北京");
		hs88.put(new Student("李四",24),"北京");
		hs88.put(new Student("李四",25),"广州");
		hs88.put(new Student("王五",26),"深圳");

		
		HashMap<Student, String> hs99=new HashMap<>();
		hs99.put(new Student("唐生",1023),"北京");
		hs99.put(new Student("孙悟空",1024),"北京");
		hs99.put(new Student("猪八戒",1025),"广州");
		hs99.put(new Student("沙和尚",1026),"深圳");
		
		HashMap<HashMap<Student, String>, String> hm=new HashMap<>();
		hm.put(hs88, "第88期基础班");
		hm.put(hs99, "第99期基础班");
		
		for (HashMap<Student, String> map1 : hm.keySet()) {//hm.keySet()代表双列集合中键的集合
			String s=hm.get(map1);//get(map1)根据键集合获取值对象
			System.out.println(s);
			for (Student skey : map1.keySet()) {
				System.out.println(skey+"="+map1.get(skey));
				
			}
		}

	}

}

猜你喜欢

转载自blog.csdn.net/qq_24644517/article/details/83090929