package com.heima.code;
import java.awt.List;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
/*
map扩展知识
map集合被使用时因为具备映射关系。
"yuere" StudentTest01("01","zhangsan")
"yuere" StudentTest01("02","lisi")
"jiuye" StudentTest01("01","wangwu")
"jiuye" StudentTest01("02","zhaoliu")
* */
class StudentTest01 {
private String id;
private String name;
StudentTest01(String id,String name){
this.id = id;
this.name = name;
}
public String toString(){
return id+"----"+name;
}
}
public class MapDemo06 {
public static void demo(){
HashMap<String,ArrayList<StudentTest01>> czbk = new HashMap<String,ArrayList<StudentTest01>>();
ArrayList<StudentTest01> yure = new ArrayList<StudentTest01>();
ArrayList<StudentTest01> jiuye = new ArrayList<StudentTest01>();
czbk.put("yure", yure);
czbk.put("jieye", jiuye);
yure.add(new StudentTest01("01","zhangsan"));
yure.add(new StudentTest01("02","lisi"));
jiuye.add(new StudentTest01("01","wanwu"));
jiuye.add(new StudentTest01("02","zhaoliu"));
Iterator<String> it = czbk.keySet().iterator();
while(it.hasNext()){
String roomName = it.next();
ArrayList<StudentTest01> room = czbk.get(roomName);
System.out.println(roomName);
getInfos(room);
}
}
public static void getInfos(ArrayList<StudentTest01> list){
Iterator<StudentTest01> it = list.iterator();
while(it.hasNext()){
StudentTest01 s = it.next();
System.out.println(s);
}
}
public static void main(String[] args) {
demo();
}
public static void getStudentTest01Info(HashMap<String,String> roomMap){
Iterator<String> it = roomMap.keySet().iterator();
while(it.hasNext()){
String id = it.next();
String name = roomMap.get(id);
System.out.println(id+":"+name);
}
}
}
|
|