日期:2014-05-20 浏览次数:20727 次
import java.util.*; class Student { private String id; private String name; public Student(String id, String name) { this.id = id; this.name = name; } } class MapTest03 { public static void main(String[] args) { Map<String, String> yuren = new HashMap<String, String>(); //预热班 Map,有好多学生映射 yuren.put("01", "zhangsa"); yuren.put("02", "lisijin"); yuren.put("03", "wangcai"); Map<String, String> jiuye = new HashMap<String, String>(); //就业班 Map,有好多学生映射 jiuye.put("01", "zhaoliu"); jiuye.put("02", "huagang"); jiuye.put("03", "pingang"); Map<String, Map<String, String>> czbk = new HashMap<String, Map<String, String>>(); //czbk 是个大 Map,有好多班级映射 czbk.put("yurenban", yuren); czbk.put("jiuyeban", jiuye); Set<Map.Entry<String, Map<String, String>>> entryset01 = czbk.entrySet(); //班级集合 Iterator<Map.Entry<String, Map<String, String>>> it01 = entryset01.iterator(); //班级迭代器 while(it01.hasNext()) { Map.Entry<String, Map<String, String>> me01 = it01.next(); String banid = me01.getKey(); Map ban = me01.getValue(); Set<Map.Entry<String, String>> entryset02 = ban.entrySet(); //学生集合 Iterator<Map.Entry<String, String>> it02 = entryset02.iterator(); //学生迭代器 while(it02.hasNext()) { Map.Entry<String, String> me02 = it02.next(); String id = me02.getKey(); String name = me02.getValue(); System.out.println(banid + "---" + id + "---" + name); } } } }