标签:传智播客 调用 assm asn put entry 例子 rgs port
package cn.meicong.DecDemo08;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
public class MapMapDemo {
public static void main(String[] args) {
HashMap<String, String> javase = new HashMap<String, String>();
javase.put("001", "张三");
javase.put("002", "李四");
HashMap<String, String> javaee = new HashMap<String, String>();
javaee.put("001", "王五");
javaee.put("002", "赵柳");
Map<String, HashMap<String, String>> czbk =
new HashMap<String, HashMap<String, String>>();
czbk.put("基础班", javase);
czbk.put("就业班", javaee);
//KeySet(czbk);
entrySet(czbk);
}
public static void entrySet(Map<String, HashMap<String, String>> czbk) {
//调用czbk的entrySet()将键值关系对象存储到Set 集合中
Set<Map.Entry<String, HashMap<String, String>>> classNameSet =
czbk.entrySet();
//迭代Set集合
Iterator<Map.Entry<String, HashMap<String, String>>> classNameIt =
classNameSet.iterator();
while(classNameIt.hasNext()) {
//classNameIt 调用next()获取键值对象
Map.Entry<String, HashMap<String, String>> classNameEntry = classNameIt.next();
//通过getKey()获取班名
String className = classNameEntry.getKey();
//通过getValue()方法获取班级集合
HashMap<String, String> studentMap = classNameEntry.getValue();
//将结合的键值对象存储到Set 集合中
Set<Map.Entry<String, String>> studentSet =studentMap.entrySet();
//迭代Set集合
Iterator<Map.Entry<String,String>> studentIt = studentSet.iterator();
while(studentIt.hasNext()) {
//studentIt 调用 next()获取键值关系
Map.Entry<String, String> studentEntry= studentIt.next();
String numKey = studentEntry.getKey();
String nameValue = studentEntry.getValue();
System.out.println(className+"\t"+numKey+"\t"+nameValue);
}
}
}
public static void KeySet(Map<String, HashMap<String, String>> czbk) {
//调用czbk的KeySet()将键存储到Set集合中
Set<String> set = czbk.keySet();
//迭代Set集合
Iterator<String> it = set.iterator();
while(it.hasNext()) {
//className 为Set集合中 元素,czbk的键
String classNameKey = it.next();
//czbk集合的方法get获取,值是HashMap的集合
HashMap<String,String> classMap = czbk.get(classNameKey);
//调用classMap的方法KeySet,存储到Set集合
Set<String> studentNum = classMap.keySet();
Iterator<String> studentIt = studentNum.iterator();
while(studentIt.hasNext()) {
//调用studentIt.next()获取的是classMapd的键,学号
String numKey =studentIt.next();
//调用classMap集合中的get方法获取值
String nameValue = classMap.get(numKey);
System.out.println(classNameKey+"\t"+numKey+"\t"+nameValue);
}
}
}
}
//来自传智播客视频
标签:传智播客 调用 assm asn put entry 例子 rgs port
原文地址:https://www.cnblogs.com/mccnblogs/p/10225372.html