A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© continuer 中级黑马   /  2015-12-28 23:20  /  609 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

需求:
         * 双元课堂有很多基础班
         * 第88期基础班定义成一个双列集合,键是学生对象,值是学生的归属地
         * 第99期基础班定义成一个双列集合,键是学生对象,值是学生的归属地

         * 无论88期还是99期都是班级对象,所以为了便于统一管理,把这些班级对象添加到双元课堂集合中
class  Demo_HashMap{
          public static void main(Strin[] args){
                  HashMap<Student, String> hm88 = new HashMap<>();
                hm88.put(new Student("蜘蛛精", 123), "盘丝洞");
                hm88.put(new Student("女儿国国王", 24), "女儿国");
                hm88.put(new Student("大鹏鸟", 532), "灵山");
               

                HashMap<Student, String> hm99 = new HashMap<>();
                hm99.put(new Student("唐僧", 23), "大唐");
                hm99.put(new Student("孙悟空",587), "花果山");
                hm99.put(new Student("猪八戒",516), "高老庄");
                hm99.put(new Student("沙和尚",564), "流沙河");
               

                HashMap<HashMap<Student, String>, String> hm = new HashMap<>();
                hm.put(hm88, "第88期基础班");
                hm.put(hm99, "第99期基础班");

               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(value+"="+ value + "=" + value2)
                      }
                }
   
          }
}

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马