集合的嵌套

本文通过具体示例展示了Java中HashMap、ArrayList及Student类的使用方法,包括元素的添加、获取以及遍历等操作,有助于理解Java集合框架的运用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


HashMap<String,HashMap<String,Integer>> hm = new HashMap<String,HashMap<String,Integer>>();
HashMap<String,Integer> hm1 = new HashMap<String,Integer>();
hm1.put("曹操",25);
hm1.put("周瑜",20);
HashMap<String,Integer> hm2 = new HashMap<String,Integer>();
hm2.put("贾宝玉",21);
hm2.put("林黛玉",18);
hm.put("三国",hm1);
hm.put("红楼梦",hm2);
//1.得到键的集合hm1 hm2
Set<String> keyset1 = hm.keySet();
//2.遍历键的集合
for(String key1 : keyset1){
	//3.得到键值对对象
	HashMap<String,Integer> keyvalue = hm.get(key1);
	  //4.得到键的集合曹操 周瑜 贾宝玉 林黛玉
	  Set<String> keyset2 = keyvalue.keySet();
	  //5.再次遍历键的集合
	  for(String key2 : keyset2){
			//6.根据键得到值25 20 21 18
			Integer value = keyvalue.get(key2);
			System.out.println("\t"+key2+"---"+value);
	  } 
}
--------------------------
HashMap<String, ArrayList<String>> hm = new HashMap<String, ArrayList<String>>();
ArrayList<String> al1 = new ArrayList<String>();
al1.add("曹操");
al1.add("周瑜");
ArrayList<String> al2 = new ArrayList<String>();
al2.add("贾宝玉");
al2.add("林黛玉");
ArrayList<String> al3 = new ArrayList<String>();
al3.add("孙悟空");
al3.add("唐僧");
//1.得到键al1 al2 al3
Set<String> keyset = hm.keySet();
//2.遍历键的集合
for(String  key : keyset){
	//3.根据键得到值的集合
	ArrayList<String> value = hm.get(key);
	//4.遍历值的集合
	for(String s : value){
		System.out.println("\t"+s);
	}
}
----------------------------------
ArrayList<HashMap<String, String>> al = new ArrayList<HashMap<String, String>>();
HashMap<String, String> hm1 = new HashMap<String, String>();
hm1.put("周瑜","小乔");
hm1.put("吕布","貂蝉");
al.add(hm1);
HashMap<String, String> hm2 = new HashMap<String, String>();
hm2.put("郭靖","黄蓉");
hm2.put("杨过","小龙女");
al.add(hm2);
HashMap<String, String> hm3 = new HashMap<String, String>();
hm3.put("令狐冲","任盈盈");
hm3.put("林平之","岳灵珊");
al.add(hm3);
//1.遍历键的集合
for(HashMap<String, String> hm : al){
	//2.得到键的集合hm1 hm2 hm3
	Set<String> keyset = hm.keySet();
	//3.遍历键的集合
	for(String key : keyset){
	   //4.根据键得到值
		String value = hm.get(key);
		System.out.println(key + "---" + value);
	}
}
------------------------
HashMap<String, HashMap<String, ArrayList<Student>>> hm = new HashMap<String, HashMap<String, ArrayList<Student>>>();
	HashMap<String, ArrayList<Student>> hm1 = new HashMap<String, ArrayList<Student>>();
		ArrayList<Student> array1 = new ArrayList<Student>();
		Student s1 = new Student("刘备", 27);
		Student s2 = new Student("关羽", 30);
		array1.add(s1);
		array1.add(s2);
		ArrayList<Student> array2 = new ArrayList<Student>();
		Student s3 = new Student("曹操", 28);
		Student s4 = new Student("典韦", 30);
		array2.add(s3);
		array2.add(s4);
	hm1.put("汉",array1);
	hm1.put("魏",array2);
hm.put("三国",hm1);

HashMap<String, ArrayList<Student>> hm2= new HashMap<String, ArrayList<Student>>();
		ArrayList<Student> array3 = new ArrayList<Student>();
		Student s5 = new Student("唐僧", 27);
		Student s6 = new Student("孙悟空", 30);
		array1.add(s5);
		array1.add(s6);
		ArrayList<Student> array4 = new ArrayList<Student>();
		Student s7 = new Student("白骨精", 28);
		Student s8 = new Student("蜘蛛精", 30);
		array2.add(s7);
		array2.add(s8);
	hm2.put("师徒",array3);
	hm2.put("妖怪",array4);
hm.put("西游",hm2);

//得到键的集合三国 西游
Set<String> keyset1 = hm.keySet();
//遍历键的集合
for (String key1 : keyset1) {
	System.out.println("key1:"+ key1);
	//得到键值对对象
	HashMap<String, ArrayList<Student>> keyvalue1 = hm.get(key1);
	//得到键的集合魏 蜀 师徒 妖怪
	Set<String> keyset2 = keyvalue1.keySet();
	//遍历键的集合
	for (String key2 : keyset2) {
		System.out.println("key2:"+ key2);
		//得到对象的集合
		ArrayList<Student> keyvalue2 = keyvalue1.get(key2);
		//遍历对象的集合
		for (Student s : keyvalue2) {
			System.out.println(s.getName()+"---"+s.getAge());
		}
	}
}


一、综合实战—使用极轴追踪方式绘制信号灯 实战目标:利用对象捕捉追踪和极轴追踪功能创建信号灯图形 技术要点:结合两种追踪方式实现精确绘图,适用于工程制图中需要精确定位的场景 1. 切换至AutoCAD 操作步骤: 启动AutoCAD 2016软件 打开随书光盘中的素材文件 确认工作空间为"草图与注释"模式 2. 绘图设置 1)草图设置对话框 打开方式:通过"工具→绘图设置"菜单命令 功能定位:该对话框包含捕捉、追踪等核心绘图辅助功能设置 2)对象捕捉设置 关键配置: 启用对象捕捉(F3快捷键) 启用对象捕捉追踪(F11快捷键) 勾选端点、中心、圆心、象限点等常用捕捉模式 追踪原理:命令执行时悬停光标可显示追踪矢量,再次悬停可停止追踪 3)极轴追踪设置 参数设置: 启用极轴追踪功能 设置角度增量为45度 确认后退出对话框 3. 绘制信号灯 1)绘制圆形 执行命令:"绘图→圆→圆心、半径"命令 绘制过程: 使用对象捕捉追踪定位矩形中心作为圆心 输入半径值30并按Enter确认 通过象限点捕捉确保圆形位置准确 2)绘制直线 操作要点: 选择"绘图→直线"命令 捕捉矩形上边中点作为起点 捕捉圆的上象限点作为终点 按Enter结束当前直线命令 重复技巧: 按Enter可重复最近使用的直线命令 通过圆心捕捉和极轴追踪绘制放射状直线 最终形成完整的信号灯指示图案 3)完成绘制 验证要点: 检查所有直线是否准确连接圆心和象限点 确认极轴追踪的45度增量是否体现 保存绘图文件(快捷键Ctrl+S)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ZHOU_VIP

您的鼓励将是我创作最大的动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值