需求:
//计算机学院有两个专业 网络工程和软件工程
//软件工程有两个班
//一班有: xbh 20 lzc 21
//二班有: mfc 21 wlx 20
// 网络工程有两个班
//一班有: hql 20 jxf 21
//二班有: zsp 21 lfl 20
// 要求用HashMap储存1-2级用Arraylist存储底层
什么也不多bb了直接贴代码,困了:
package cn.zsp.map_study_07;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Set;
//计算机学院有两个专业 网络工程和软件工程
//软件工程有两个班
//一班有: xbh 20 lzc 21
//二班有: mfc 21 wlx 20
// 网络工程有两个班
//一班有: hql 20 jxf 21
//二班有: zsp 21 lfl 20
// 要求用HashMap储存1-2级用Arraylist存储底层
public class ThirdHashMap {
public static void main(String[] args) {
HashMap<String,HashMap<String, ArrayList<Student>>> jk=new HashMap<String,HashMap<String, ArrayList<Student>>>();
HashMap<String, ArrayList<Student>> wlgc =new HashMap<String, ArrayList<Student>>();
HashMap<String, ArrayList<Student>> rjgc =new HashMap<String, ArrayList<Student>>();
ArrayList<Student> class01 =new ArrayList<Student>();
ArrayList<Student> class02 =new ArrayList<Student>();
ArrayList<Student> class11 =new ArrayList<Student>();
ArrayList<Student> class12 =new ArrayList<Student>();
class01.add(new Student("xbh",24));
class01.add(new Student("lzz",25));
class02.add(new Student("mfc",24));
class02.add(new Student("wlx",20));
class11.add(new Student("hql",20));
class11.add(new Student("jxf",21));
class12.add(new Student("zsp",21));
class12.add(new Student("lfl",20));
rjgc.put("一班",class01);
rjgc.put("二班",class02);
wlgc.put("一班",class11);
wlgc.put("二班",class12);
jk.put("网络工程",wlgc);
jk.put("软件工程",rjgc);
Set<String> jkset =jk.keySet();
for (String jkkey :jkset)
{
System.out.println(jkkey);
Set <String>departmentset =jk.get(jkkey).keySet();
for (String departmentkey :departmentset )
{
System.out.println(departmentkey);
for (Student student : jk.get(jkkey).get(departmentkey) ){
System.out.println(student.getName()+"----年龄是:"+student.getAge());
}
}
}
}
}