java Hashmap Map TreeMap traverse several ways, the most complete whole network, the whole network of the strongest
package Collec2; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Map.Entry; import java.util.Set; public class Test1 { public static void main(String[] args) { HashMap<Student, String> hashmap_88 = new HashMap<Student, String>(); hashmap_88.put(new Student("张三", 23), "北京"); hashmap_88.put(new Student("李四", 24), "南京"); HashMap<Student, String> = hashmap_99 new new HashMap <Student, String> (); hashmap_99.put ( new new Student ( "King of Five", 23), "Shanghai" ); hashmap_99.put ( new new Student ( "Zhao six", 24 ), "Shenzhen" ); HashMap <HashMap <Student, String>, String> HM = new new HashMap <HashMap <Student, String>, String> (); hm.put (hashmap_88, "on the basis of 88 classes" ); hm.put (hashmap_99, "on the basis of 99 classes" ); System.out.println ( "traversing a way" ); the Set <HashMap <Student,String>> ks = hm.keySet(); Iterator<HashMap<Student, String>> it1 = ks.iterator(); while(it1.hasNext()) { HashMap<Student,String> next_stu_value = it1.next(); Set<Student> stu_set = next_stu_value.keySet(); Iterator<Student> stu_it = stu_set.iterator(); System.out.println(hm.get(next_stu_value)+"有以下学生"); while(stu_it.hasNext()) { Student student = stu_it.next(); System.out.println("个人信息"+student); } } System.out.println("遍历方式二"); for (HashMap<Student, String> hashMap : hm.keySet()) { System.out.println(hm.get(hashMap)+"有以下学生"); for (Student stu : hashMap.keySet()) { System.out.println("个人信息"+stu); } } System.out.println("遍历方式三"); Set<HashMap<Student,String>> x=hm.keySet(); for(Iterator<HashMap<Student,String>> it= x.iterator();it.hasNext();) { HashMap<Student, String> stu_map_value = it.next(); System.out.println(hm.get(stu_map_value)+"有以下学生"); for( Iterator<Student> it2 = stu_map_value.keySet().iterator();it2.hasNext();) { Student student = it2.next(); System.out.println("个人信息"+student); } } System.out.println("遍历方式四"); Set<Entry<HashMap<Student,String>,String>> entrySet = hm.entrySet(); Iterator<Entry<HashMap<Student, String>, String>> itentry = entrySet.iterator(); while(itentry.hasNext()) { Entry<HashMap<Student, String>, String> entry = itentry.next(); HashMap<Student,String> map = entry.getKey(); System.out.println(entry.getValue()+"有以下学生"); Iterator<Entry<Student, String>> iterator = map.entrySet().iterator(); while(iterator.hasNext()) { Entry<Student, String> next = iterator.next(); System.out.println("个人信息"+next.getKey()+" "+next.getValue()); } } System.out.println("Traversal five" ); for (of Map.Entry <the HashMap <Student, String>, String> entry: hm.entrySet ()) { System.out.println (entry.getValue () + "following student" ); for (of Map.Entry <Student, String> STU: entry.getKey () the entrySet ().) { System.out.println ( "personal information" stu.getKey + () + "" + stu.getValue ()); } } System.out.println ( "traversal six" ); hm.forEach ((K, V) -> { System.out.println (V + "following student" ); K.forEach ((sub_K,sub_V)->{ System.out.println("个人信息"+sub_K+" "+sub_V); }); }); Iterator<HashMap<Student, String>> ite2 = hm.keySet().iterator(); while(ite2.hasNext()) { HashMap<Student,String> next = ite2.next(); Iterator<Entry<Student, String>> iterator = next.entrySet().iterator(); while(iterator.hasNext()) { Entry<Student, String> entry = iterator.next(); if(entry.getValue().equals("深圳")) { iterator.remove(); } } } System.out.println ( "- = -----------------------" ); hm.forEach ((K, V) -> { the System .out.println (V + "following student" ); K.forEach ((sub_K, sub_V) -> { System.out.println ( "personal information" sub_K + + "" + sub_V); }); }); } }