当前位置 : 主页 > 编程语言 > c++ >

集合嵌套之HashMap嵌套HashMap

来源:互联网 收集:自由互联 发布时间:2021-06-30
gistfile1.txt package day18;import java.util.HashMap;/** * 描述: * 集合嵌套之HashMap嵌套HashMap * * @outhor 71948 * @create 2017-10-08 21:37 * 需求; * 1、 */public class Demo8_HashMapHashMap { public static void main(String[] ar
gistfile1.txt
package day18;

import java.util.HashMap;

/**
 * 描述:
 * 集合嵌套之HashMap嵌套HashMap
 *
 * @outhor 71948
 * @create 2017-10-08 21:37
 * 需求;
 * 1、
 */
public class Demo8_HashMapHashMap {
    public static void main(String[] args) {
        //定义组别1
        HashMap
 
   hm1 = new HashMap<>();
        hm1.put(new Student("张三",23),"北京");
        hm1.put(new Student("李四",25),"上海");
        hm1.put(new Student("王五",25),"深圳");
        hm1.put(new Student("赵六",26),"杭州");
        hm1.put(new Student("周七",27),"广州");


        //定义组别2
        HashMap
  
    hm2 = new HashMap<>(); hm2.put(new Student("唐诗",23),"北京"); hm2.put(new Student("胖胖",25),"上海"); hm2.put(new Student("月月",25),"深圳"); hm2.put(new Student("敏敏",26),"杭州"); hm2.put(new Student("丫头",27),"广州"); //定义主类 HashMap
   
    ,String> hm = new HashMap<>(); hm.put(hm1,"组别1"); hm.put(hm2,"组别2"); //遍历集合 for (HashMap
    
      Shm : hm.keySet()) { String value = hm.get(Shm);//get(h)根据键对象获取值对象 //遍历键的集合对象 for (Student stu : Shm.keySet()) { //h.keyset是获取集合中的所有对象 String value2= Shm.get(stu); System.out.println(stu + "=" + value2 + "=" + value); } } } }
    
   
  
 
网友评论