=================================stu======================================
package SetCircle; public class Stu { private int id; private String name; public Stu() { } public Stu(int id, String name) { this.id = id; this.name = name; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String toString() { return "Student{id = " + id + ", name = " + name + "}"; } }
=================================主函数==================================
package SetCircle; import java.io.FileOutputStream; import java.util.*; public class Lisesettt { // yjs stq1=new yjs(1,"嵌批一号"); // yjs stq2=new yjs(2,"嵌批二号"); // yjs stq3=new yjs(3,"嵌批三号"); // yjs stj1=new yjs(1,"高贵Java一号"); // yjs stj2=new yjs(2,"高贵Java二号"); // yjs stj3=new yjs(3,"高贵Java三号"); public static void main(String[] args) { //=========================================云计算=============================================================================================================== HashMap<String,ArrayList<Stu>> yjsclasses = new HashMap<String,ArrayList<Stu>>(); ArrayList<Stu> stu1 = new ArrayList<>(); Stu sty1=new Stu(1,"云批一号"); Stu sty2=new Stu(2,"云批二号"); Stu sty3=new Stu(3,"云批三号"); stu1.add(0,sty1); stu1.add(1,sty2); stu1.add(2,sty3); ArrayList<Stu> stu2 = new ArrayList<>(); Stu sty4=new Stu(1,"云批五号"); Stu sty5=new Stu(2,"云批六号"); Stu sty6=new Stu(3,"云批七号"); stu2.add(0,sty4); stu2.add(1,sty5); stu2.add(2,sty6); yjsclasses.put("云计算一班",stu1); yjsclasses.put("云计算二班",stu2); //================================================================================================================================================================= //=========================================C=============================================================================================================== HashMap<String,ArrayList<Stu>> cclasses = new HashMap<String,ArrayList<Stu>>(); ArrayList<Stu> stu3 = new ArrayList<>(); Stu stc1=new Stu(1,"c批一号"); Stu stc2=new Stu(2,"c批二号"); Stu stc3=new Stu(3,"c批三号"); stu3.add(0,stc1); stu3.add(1,stc2); stu3.add(2,stc3); ArrayList<Stu> stu4 = new ArrayList<>(); Stu stc4=new Stu(1,"c批五号"); Stu stc5=new Stu(2,"c批六号"); Stu stc6=new Stu(3,"c批七号"); stu4.add(0,stc4); stu4.add(1,stc5); stu4.add(2,stc6); cclasses.put("c一班",stu3); cclasses.put("c二班",stu4); //================================================================================================================================================================= //=========================================C=============================================================================================================== HashMap<String,ArrayList<Stu>> jclasses = new HashMap<String,ArrayList<Stu>>(); ArrayList<Stu> stu5 = new ArrayList<>(); Stu stj1=new Stu(1,"高贵Java一号"); Stu stj2=new Stu(2,"高贵Java二号"); Stu stj3=new Stu(3,"高贵Java三号"); stu5.add(0,stj1); stu5.add(1,stj2); stu5.add(2,stj3); ArrayList<Stu> stu6 = new ArrayList<>(); Stu stj4=new Stu(1,"高贵Java五号"); Stu stj5=new Stu(2,"高贵Java六号"); Stu stj6=new Stu(3,"高贵Java七号"); stu6.add(0,stj4); stu6.add(1,stj5); stu6.add(2,stj6); jclasses.put("j一班",stu5); jclasses.put("j二班",stu6); // Set<Map.Entry<String,ArrayList<Stu>>> entrySet= jDirection.entrySet(); // for (Map.Entry<String,ArrayList<Stu>> entry: entrySet){ // System.out.println("班级名称:"+entry.getKey()+ // "学生信息"+entry.getValue()); // } //=========================================================================================================================================== HashMap<String,HashMap<String,ArrayList<Stu>>> yjsclass =new HashMap<String,HashMap<String,ArrayList<Stu>>>(); HashMap<String,HashMap<String,ArrayList<Stu>>> cclass =new HashMap<String,HashMap<String,ArrayList<Stu>>>(); HashMap<String,HashMap<String,ArrayList<Stu>>> jclass =new HashMap<String,HashMap<String,ArrayList<Stu>>>(); yjsclass.put("云计算班级:",yjsclasses); cclass.put("c班级:",cclasses); jclass.put("j班级:",jclasses); HashMap<String, HashMap<String,HashMap<String,ArrayList<Stu>>>> direction = new HashMap(); direction.put("云计算方向:",yjsclass); direction.put("c方向:",cclass); direction.put("java方向:",jclass); ArrayList<HashMap<String, HashMap<String,HashMap<String,ArrayList<Stu>>>>> school =new ArrayList<>(); school.add(direction); Iterator<HashMap<String, HashMap<String, HashMap<String, ArrayList<Stu>>>>> school_it = school.iterator();//定义迭代器获取数据 while (school_it.hasNext()){ HashMap<String, HashMap<String, HashMap<String, ArrayList<Stu>>>> fx = school_it.next();//获取每个数据 Set<HashMap.Entry<String,HashMap<String,HashMap<String,ArrayList<Stu>>>>> fx_entry = fx.entrySet();//获去每个数据的键值对 Iterator<HashMap.Entry<String, HashMap<String, HashMap<String, ArrayList<Stu>>>>> fx_entry_it = fx_entry.iterator();//使用迭代器遍历键值对 while (fx_entry_it.hasNext()){ HashMap.Entry<String, HashMap<String, HashMap<String, ArrayList<Stu>>>> fx_element =fx_entry_it.next();//获取键值对 System.out.println("学校方向:"+fx_element.getKey()); HashMap<String,HashMap<String,ArrayList<Stu>>> banji = fx_element.getValue(); Set<HashMap.Entry<String,HashMap<String,ArrayList<Stu>>>> banji_entry =banji.entrySet(); Iterator<HashMap.Entry<String,HashMap<String,ArrayList<Stu>>>> banji_entry_it =banji_entry.iterator(); while (banji_entry_it.hasNext()){ HashMap.Entry<String,HashMap<String,ArrayList<Stu>>> banji_element = banji_entry_it.next(); System.out.println("班级:"+banji_element.getKey()); HashMap<String,ArrayList<Stu>> difclass =banji_element.getValue(); Set<Map.Entry<String,ArrayList<Stu>>> difclass_entry =difclass.entrySet(); Iterator<Map.Entry<String, ArrayList<Stu>>> difclass_entry_it = difclass_entry.iterator(); while (difclass_entry_it.hasNext()){ Map.Entry<String, ArrayList<Stu>> difclass_element =difclass_entry_it.next(); System.out.println("班级名称:"+difclass_element.getKey()); ArrayList<Stu> xuesheng = difclass_element.getValue(); for (Stu stu :xuesheng){ System.out.print("id"+stu.getId()+" "); System.out.print("name:"+stu.getName()+" "); } System.out.println(); } } } }