Map的嵌套   练习

利用迭代和增强for循环的两种方式实现如下效果

package cn.ccc;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.Set;

public class two {
public static void main(String[] args) {
//定义java班的集合
HashMap<String, String> java = new HashMap<String, String>();
//向班级存储学生
java.put("20190322", "第一名");
java.put("20190323", "第二名");
java.put("20190324", "第三名");
//定义Dhoop班的集合
HashMap<String, String> Dhoop = new HashMap<String,String>();
//向Dhoop班级存储学生
Dhoop.put("20190401", "第一名");
Dhoop.put("20190402", "第二名");
Dhoop.put("20190403", "第三名");
//定义集合aa容器 键是班级的名字 值是两个班级的容器
HashMap<String, HashMap<String, String>> aa = new HashMap<String,HashMap<String, String>>();
aa.put("java班", java);
aa.put("Dhoop班", Dhoop);
EntrySet(aa);
}

private static void EntrySet(HashMap<String, HashMap<String, String>> aa) {
//调用集合aa的方法entrySet将aa集合的键封装到Set集合中
Set<Entry<String, HashMap<String, String>>> classenset = aa.entrySet();
//迭代Set集合
Iterator<Entry<String, HashMap<String, String>>> it = classenset.iterator();

while(it.hasNext()){
Entry<String, HashMap<String, String>> classnext = it.next();
String classkey = classnext.getKey();
HashMap<String, String> classvalue = classnext.getValue();
System.out.println(classkey);
///
Set<Entry<String, String>> studentset = classvalue.entrySet();
Iterator<Entry<String, String>> studentit = studentset.iterator();
while(studentit.hasNext()){
Entry<String, String> studentnext = studentit.next();
String numk = studentnext.getKey();
String numv = studentnext.getValue();
System.out.println(numk+" "+numv);

}
}
System.out.println(".........................................................");
//增强for循环
Set<Entry<String, HashMap<String, String>>> forclassset = aa.entrySet();
for(Entry<String, HashMap<String, String>> i:forclassset){
String classk = i.getKey();
HashMap<String, String> classv = i.getValue();
Set<Entry<String, String>> forstudentset = classv.entrySet();
System.out.println(classk);
for(Entry<String, String> j:forstudentset){
String numkey = j.getKey();
String numvalue = j.getValue();
System.out.println(numkey+" "+numvalue);
}
}

}
}

Map的嵌套 练习的更多相关文章

  1. 水果(map的嵌套)

    夏天来了~~好开心啊,呵呵,好多好多水果~~ Joe经营着一个不大的水果店.他认为生存之道就是经营最受顾客欢迎的水果.现在他想要一份水果销售情况的明细表,这样Joe就可以很容易掌握所有水果的销售情况了 ...

  2. Map的嵌套,HDU(1263)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1263 新学的map的嵌套 #include <stdio.h> #include < ...

  3. 双列集合Map的嵌套遍历

    双列集合Map的嵌套使用,例如HashMap中还有一个HashMap,这样的集合遍历起来稍微有点儿复杂.例如一个集合:HashMap<Integer,HashMap<String,Inte ...

  4. map的嵌套 + 例题(水果)

    水果 http://acm.hdu.edu.cn/showproblem.php?pid=1263 Problem Description 夏天来了~~好开心啊,呵呵,好多好多水果~~Joe经营着一个 ...

  5. Map接口----Map中嵌套Map

    package cn.good.com; import java.util.HashMap; import java.util.Iterator; import java.util.Map; impo ...

  6. Map的嵌套

    package cn.lijun.demo2; import java.util.HashMap; import java.util.Iterator; import java.util.Set; p ...

  7. Map的嵌套使用

    Map嵌套Map: 例: AAA: Javas班: 001 熊大 002 熊二 Hdoop班 001 小猪猪 002 小菲菲 ★使用增强for循环遍历Set数组: import java.util.H ...

  8. fastjson排序 Map多层嵌套转换自动排序问题终极解决方案

    阅读更多 最近项目中用到了fastjson(1.2.15)需要将前端多层嵌套json转换为map,由于map的无序性,想了很多办法,最终找到使用 Map m= JSONArray.parseObjec ...

  9. golang map多层嵌套使用及遍历方法汇总

    原文:https://blog.csdn.net/boyhandsome7/article/details/79734847 ------------------------------------- ...

随机推荐

  1. hdu1098

    Ignatius is poor at math,he falls across a puzzle problem,so he has no choice but to appeal to Eddy. ...

  2. java按照指定格式输出系统时间使用SimpleDateFormat方法

    public class TimeThree { public static void main(String[] args) { SimpleDateFormat d = new SimpleDat ...

  3. Ubuntu18下sudo apt install xxx出现问题

    当执行sudo apt install rpm时失败(apt-get也失败),输出如下报错信息: E: Could not get lock /var/lib/dpkg/lock - open (11 ...

  4. Django基础-01

    Django 是基于 Python,所有的 Django 代码都是用Python写成的. Django 特点 强大的数据库功能 拥有强大的数据库操作接口(QuerySet API),如需要也能执行原生 ...

  5. 201671010142 2017-2 《java第八章学习感悟》

    泛型程序设计 学会如何定义简单泛型类,引入了一个变量T,用<>,并放在类名的后面. 如何定义一个带有类型参数的简单方法.当调用一个泛型方法时,在方法名前的尖括号中放入具体的类型.

  6. jsapi 调起微信支付的的踩坑

    问题: 公众微信号调起微信支付的时候,有的时候调起支付成功,有的时候调起支付失败.利用抓包工具抓取数据显示授权和调用后台的微信预支付订单接口都成功并且都返回正确的数据.但是调起支付的时候传入的data ...

  7. mysql 的快速入门

    1.数据库的操作 1)查看数据库:show databases; 2)使用数据库:use 数据库名: 3)创建数据库:create database 数据库名: 4)查看创建数据库的sql语句:sho ...

  8. Input禁用文本框

    <input type="text" readonly="readonly" /> readonly:只读属性:

  9. Bootstrap 总结

     Bootstrap 首先要引入下面三个文件   <!-- 新 Bootstrap 核心 CSS 文件 --> <link href="https://cdn.bootcs ...

  10. 18-09-13 机器人和服务器之间的ip配置和脚本的重启

    问题9 服务器安装完毕后 怎么配置机器人客户端的配置ip