zoukankan      html  css  js  c++  java
  • 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]=第二期基础班
            }
          }
        }
      }

  • 相关阅读:
    lua的多种实现方式(1-100的和)
    51单片机交通灯(定时器+38译码器+中断)
    51单片机定时器实现LED闪烁
    51单片机0号与1号外部中断实例
    51单片机:IO口扩展芯片用法(74HC165,74HC595)
    mybatis org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
    Intellij IDEA运行报Command line is too long解法
    Jmeter命令行运行实例讲解
    Windows10在当前目录快速打开cmd的方法
    Jmeter接口测试对json串中的值进行断言
  • 原文地址:https://www.cnblogs.com/zhujialei123/p/9038231.html
Copyright © 2011-2022 走看看