package demo13;import java.util.ArrayList;import java.util.HashMap;import java.util.Set;public class nestdemo {public static void main(String[] args) { HashMap<String,HashMap<String,ArrayList<Student>>> 全國=new HashMap<String,HashMap<String,ArrayList<Student>>>(); //河南地區(qū) HashMap<String,ArrayList<Student>> 河南地區(qū)=new HashMap<String,ArrayList<Student>>(); ArrayList<Student> 高校區(qū)=new ArrayList<Student>(); Student one=new Student("路人1",18); Student two=new Student("路人2",18); 高校區(qū).add(one); 高校區(qū).add(two); 河南地區(qū).put("河南", 高校區(qū)); ArrayList<Student> 低校區(qū)=new ArrayList<Student>(); Student one1=new Student("路人3",18); Student two1=new Student("路人4",18); 低校區(qū).add(one1); 低校區(qū).add(two1); 河南地區(qū).put("河南", 低校區(qū)); 全國.put("河南地區(qū)數(shù)據(jù):", 河南地區(qū)); //北京地區(qū) HashMap<String,ArrayList<Student>>北京地區(qū)=new HashMap<String,ArrayList<Student>>(); ArrayList<Student> 北京高校區(qū)=new ArrayList<Student>(); Student one11=new Student("路人1",18); Student two11=new Student("路人2",18); 高校區(qū).add(one11); 高校區(qū).add(two11); 河南地區(qū).put("北京", 北京高校區(qū)); ArrayList<Student> 北京低校區(qū)=new ArrayList<Student>(); Student one3=new Student("路人3",18); Student two4=new Student("路人4",18); 低校區(qū).add(one3); 低校區(qū).add(two4); 河南地區(qū).put("河南", 北京低校區(qū)); 全國.put("北京地區(qū)數(shù)據(jù):", 北京地區(qū)); //遍歷 Set<String> 總key=全國.keySet(); for(String key:總key){ System.out.println(key); HashMap<String, ArrayList<Student>> value=全國.get(key); Set<String> 分地區(qū)value= value.keySet(); for(String key2: 分地區(qū)value){ System.out.println("來過"); ArrayList<Student> 校區(qū)value=value.get(key2); for(Student 學(xué)生value: 校區(qū)value){ System.out.println("也來過");//此處不顯示 System.out.println("\t"+學(xué)生value.getName()+"\t"+學(xué)生value.getAge()); } } ? ? }}}
最后到遍歷學(xué)生時遍歷不出來???
實(shí)力走天下
2017-05-28 18:48:55