• HashMap之集合嵌套


    package com.day15.Map;
    /*
    * HashMap嵌套HashMap
    */

    import java.util.HashMap;

    import com.day15.bean.Student;

      public class HashMap_Two {

        public static void main(String[] args) {
          //定义1期班
          HashMap<Student, String> hm1=new HashMap<>();
          hm1.put(new Student("Kobe",20), "LA");
          hm1.put(new Student("KG",21), "Boston");
          hm1.put(new Student("PP",22), "Boston");
          hm1.put(new Student("Allen",23), "Nanjing");
          //定义2期班
          HashMap<Student, String> hm2=new HashMap<>();
          hm2.put(new Student("Zjl",20), "Nanjing");
          hm2.put(new Student("XX",21), "Dazhou");
          hm2.put(new Student("Zxc",22), "Hongkong");
          hm2.put(new Student("Ty",23), "Beijing");
          //定义专业
          HashMap<HashMap<Student,String>, String> hm=new HashMap<>();
          hm.put(hm1, "第一期基础班");
          hm.put(hm2, "第二期基础班");
          //遍历双列集合
          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(key+"="+value2+key+"="+value);//Student [name=Allen,age=23]=NanjingStudent [name=Allen,age=23]=第一期基础班
                                     //Student [name=Kobe,age=20]=LAStudent [name=Kobe,age=20]=第一期基础班
                                     //Student [name=KG,age=21]=BostonStudent [name=KG,age=21]=第一期基础班
                                     //Student [name=PP,age=22]=BostonStudent [name=PP,age=22]=第一期基础班
                                     //Student [name=Zxc,age=22]=HongkongStudent [name=Zxc,age=22]=第二期基础班
                                     //Student [name=Zjl,age=20]=NanjingStudent [name=Zjl,age=20]=第二期基础班
                                     //Student [name=XX,age=21]=DazhouStudent [name=XX,age=21]=第二期基础班
                                     //Student [name=Ty,age=23]=BeijingStudent [name=Ty,age=23]=第二期基础班
            }
          }
        }
      }

  • 相关阅读:
    Eclipse 常用快捷键
    asp.net中如何计算中英文混合字符串长度
    图片水印的类库
    开源asp.net SNS源码下载地址
    eclipse修改编辑器字体 + Eclipse自动提示(Content Assist) + Eclipse汉化
    eclipse内部Javadoc怎么汉化成中文
    Eclipse设置输入智能提示
    Oracle建立表空间和用户
    王福朋asp.net2.0 petshop4.0系列视频教程的下载地址
    【转】在Eclipse中设置中文JavaDOC
  • 原文地址:https://www.cnblogs.com/zhujialei123/p/9038231.html
Copyright © 2020-2023  润新知