• HashMap的嵌套应用


    public class HashMapDemo3 {
    public static void main(String[] args) {
    //
    HashMap<String,HashMap<String,ArrayList<Student>>> czbkMap=new HashMap<String,HashMap<String,ArrayList<Student>>>();
    //北京校区
    HashMap<String,ArrayList<Student>> bjCzbkMap=new HashMap<String,ArrayList<Student>>();
    ArrayList<Student> array1=new ArrayList<Student>();
    Student bs1=new Student("jc张三",20);
    Student bs2=new Student("jc李四",21);
    array1.add(bs1);
    array1.add(bs2);
    ArrayList<Student> array2=new ArrayList<Student>();
    Student bs3=new Student("jy张三",20);
    Student bs4=new Student("jy李四",21);
    array2.add(bs3);
    array2.add(bs4);

    bjCzbkMap.put("基础班", array1);
    bjCzbkMap.put("就业班", array2);

    czbkMap.put("北京校区", bjCzbkMap);

    // System.out.println(czbkMap);
    //上海校区
    HashMap<String,ArrayList<Student>> shCzbkMap=new HashMap<String,ArrayList<Student>>();
    ArrayList<Student> array3=new ArrayList<Student>();
    Student ss1=new Student("jc张三",20);
    Student ss2=new Student("jc李四",21);
    array3.add(ss1);
    array3.add(ss2);
    ArrayList<Student> array4=new ArrayList<Student>();
    Student ss3=new Student("jy张三",20);
    Student ss4=new Student("jy李四",21);
    array4.add(ss3);
    array4.add(ss4);

    shCzbkMap.put("基础班", array3);
    shCzbkMap.put("就业班", array4);

    czbkMap.put("上海校区", shCzbkMap);


    //武汉校区
    HashMap<String,ArrayList<Student>> whCzbkMap=new HashMap<String,ArrayList<Student>>();
    ArrayList<Student> array5=new ArrayList<Student>();
    Student ws1=new Student("jc张三",20);
    Student ws2=new Student("jc李四",21);
    array5.add(ws1);
    array5.add(ws2);
    ArrayList<Student> array6=new ArrayList<Student>();
    Student ws3=new Student("jy张三",20);
    Student ws4=new Student("jy李四",21);
    array6.add(ws3);
    array6.add(ws4);

    whCzbkMap.put("基础班", array1);
    whCzbkMap.put("就业班", array2);

    czbkMap.put("武汉校区", whCzbkMap);


    //广州校区
    HashMap<String,ArrayList<Student>> gzCzbkMap=new HashMap<String,ArrayList<Student>>();
    ArrayList<Student> array7=new ArrayList<Student>();
    Student gs1=new Student("jc张三",20);
    Student gs2=new Student("jc李四",21);
    array7.add(gs1);
    array7.add(gs2);
    ArrayList<Student> array8=new ArrayList<Student>();
    Student gs3=new Student("jy张三",20);
    Student gs4=new Student("jy李四",21);
    array8.add(gs3);
    array8.add(gs4);

    gzCzbkMap.put("基础班", array7);
    gzCzbkMap.put("就业班", array8);

    czbkMap.put("广州校区", gzCzbkMap);

    //遍历集合
    Set<String> czbkMapSet=czbkMap.keySet();

    for(String strKey:czbkMapSet ){
    HashMap<String,ArrayList<Student>> czbkMapSetValue=czbkMap.get(strKey);
    System.out.println(strKey);
    Set<String> czbkMapValueSet=czbkMapSetValue.keySet();
    for(String studentKey:czbkMapValueSet){
    ArrayList<Student> arr=czbkMapSetValue.get(studentKey);
    System.out.println(" "+studentKey);
    for(Student s:arr){
    System.out.println(" "+s.getName()+"--------"+s.getAge());
    }

    }
    }
    }
    }

  • 相关阅读:
    脚本输出EBMIDE——断点跟踪输出
    框架配置Winter framework 高效灵活的请求处理框架
    项目经理微软第一份实习
    事件编辑器ScriptCase中的PHP代码编辑器
    命令服务删除virtual bridge
    ajax前台asp.net利用Ajax和Jquery在前台向后台传参数并返回值
    概率数据HDU1203 I NEED A OFFER!(0、1背包)
    控件当前日期android控件之DatePicker和TimePicker
    输入命令xalan初步学习
    函数接口Inside COM读书笔记调度接口与自动化
  • 原文地址:https://www.cnblogs.com/liumin-txgt/p/13403806.html
Copyright © 2020-2023  润新知