/*
Map扩展知识。
map集合被使用是因为具备映射关系。
一个学校有多个教室,每一个教室都有名称。
*/
import java.util.*;
class MapDemo3
{
public static void main(String[] args)
{
HashMap<String,HashMap<String,String>> czbk = new HashMap<String,HashMap<String,String>>();
HashMap<String,String> yure = new HashMap<String,String>();
HashMap<String,String> jiuye = new HashMap<String,String>();
czbk.put("yureban",yure);
czbk.put("jiuyeban",jiuye);
yure.put("01","zhangsan");
yure.put("02","lisi");
jiuye.put("01","zhaoliu");
jiuye.put("02","wangwu");
//遍历czbk集合,获取所有的教室。
Iterator<String> it = czbk.keySet().iterator();
while(it.hasNext())
{
String roomName = it.next();
HashMap<String,String> room = czbk.get(roomName);
System.out.println(roomName);
getStudentInfo(room);
}
//getStudentInfo(jiuye);
}
public static void getStudentInfo(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);
}
}
} |