Map的嵌套 练习
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的嵌套 练习的更多相关文章
- 水果(map的嵌套)
夏天来了~~好开心啊,呵呵,好多好多水果~~ Joe经营着一个不大的水果店.他认为生存之道就是经营最受顾客欢迎的水果.现在他想要一份水果销售情况的明细表,这样Joe就可以很容易掌握所有水果的销售情况了 ...
- Map的嵌套,HDU(1263)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1263 新学的map的嵌套 #include <stdio.h> #include < ...
- 双列集合Map的嵌套遍历
双列集合Map的嵌套使用,例如HashMap中还有一个HashMap,这样的集合遍历起来稍微有点儿复杂.例如一个集合:HashMap<Integer,HashMap<String,Inte ...
- map的嵌套 + 例题(水果)
水果 http://acm.hdu.edu.cn/showproblem.php?pid=1263 Problem Description 夏天来了~~好开心啊,呵呵,好多好多水果~~Joe经营着一个 ...
- Map接口----Map中嵌套Map
package cn.good.com; import java.util.HashMap; import java.util.Iterator; import java.util.Map; impo ...
- Map的嵌套
package cn.lijun.demo2; import java.util.HashMap; import java.util.Iterator; import java.util.Set; p ...
- Map的嵌套使用
Map嵌套Map: 例: AAA: Javas班: 001 熊大 002 熊二 Hdoop班 001 小猪猪 002 小菲菲 ★使用增强for循环遍历Set数组: import java.util.H ...
- fastjson排序 Map多层嵌套转换自动排序问题终极解决方案
阅读更多 最近项目中用到了fastjson(1.2.15)需要将前端多层嵌套json转换为map,由于map的无序性,想了很多办法,最终找到使用 Map m= JSONArray.parseObjec ...
- golang map多层嵌套使用及遍历方法汇总
原文:https://blog.csdn.net/boyhandsome7/article/details/79734847 ------------------------------------- ...
随机推荐
- es6(二)
三 . 正则扩展: 1.构造函数的扩展 let regex = new Regex('xyz','i'); let regex2 = new Regex(/xyz/i);//test() 方法用于检测 ...
- Saiku根据入参日期查询出对应的数据(二十)
Saiku根据入参日期查询出对应的数据 之前好像有写过一篇博客关于saiku date range的,现在进一步更新啦!!! 这里的日期筛选会更完善一些,需要提供两个参数 开始日期与结束日期(star ...
- cookie路径问题
昨天在开发过程中用到cookie,在销毁该$.cookie('flag',null)时发现又新生成了一个同名的值为null但路径不相同的cookie 原来在设置cookie时没有给他设置路径所以该co ...
- 微信h5支付出现“商家参数格式有误,请联系商家解决”
在浏览器进行微信h5支付时出现:
- 表单传参,在action中的参数得不到
写上面这个的时候,发现传过去的url路径是这样的 在action后面的pro=login得不到. 只需要将method中的get改成post就可以了
- flink基础教程读书笔记
数据架构设计领域发生了重大的变化,基于流的处理是变化的核心. 分布式文件系统用来存储不经常更新的数据,他们也是大规模批量计算所以来的数据存储方式. 批处理架构(lambda架构)实现计数的方式:持续摄 ...
- JAVAEE 第八周
equals():反映的是对象或变量具体的值,即两个对象里面包含的值--可能是对象的引用,也可能是值类型的值. hashCode():计算出对象实例的哈希码,并返回哈希码,又称为散列函数.根类Obje ...
- "HTML编码规范" 笔记
转自学习网站(百度原创):https://github.com/ecomfe/spec/blob/master/html-style-guide.md 本文是百度培训网站上关于HTML编码规范的笔记, ...
- 前段学习的roadmap
引自http://www.cnblogs.com/IMxinu/p/9693041.html
- shell脚本判断安装包位置及类型
Log() { LogFile=/tmp/``.log LogDate=$(date +"%F %T") echo -e "\n\n||| ${LogDate} ||| ...