public class Test_4 {
public static void main(String[] args) {
Map<String, String> javase = new HashMap<String, String>();
Map<String, String> javaee = new HashMap<String, String>();
javase.put("001", "张三");
javase.put("002", "李四");
javaee.put("001", "王五");
javaee.put("002", "赵六");
Map<String, Map<String,String>> classStudy = new HashMap<String, Map<String,String>>();
classStudy.put("class one", javase);
classStudy.put("class two", javaee);
get(classStudy);
System.out.println("++++++++++++");
get1(classStudy);
System.out.println("++++++++++++");
get2(classStudy);
System.out.println("++++++++++++");
get3(classStudy);
System.out.println("++++++++++++");
get4(classStudy);
}
public static void get1(Map<String,Map<String,String>> map){
for (Map.Entry<String, Map<String,String>> entry1 : map.entrySet()) {
for (Map.Entry<String, String> entry2 : entry1.getValue().entrySet()) {
System.out.println(entry1.getKey() + "---" + entry2.getKey() +"..." + entry2.getValue());
}
}
}
public static void get2(Map<String,Map<String,String>> classStudy){
Set<Map.Entry<String, Map<String,String>>> set1 = classStudy.entrySet();
Iterator<Map.Entry<String, Map<String,String>>> it1 = set1.iterator();
while (it1.hasNext()) {
Map.Entry<String,Map<String,String>> entry1 = it1.next();
String s1 = entry1.getKey();
Map<String,String> map2 = entry1.getValue();
Set<Map.Entry<String,String>> set2 = map2.entrySet();
Iterator<Map.Entry<String,String>> it2 = set2.iterator();
while (it2.hasNext()) {
Map.Entry<String,String> entry2 = it2.next();
String s2 = entry2.getKey();
String s3 = entry2.getValue();
System.out.println(s1 + "---" + s2 + "..." + s3);
}
}
}
public static void get3(Map<String, Map<String, String>> classStudy){
Set<String> set1 = classStudy.keySet();
for (String s1 : set1) {
Map<String,String> map2 = classStudy.get(s1);
Set<String> set2 = map2.keySet();
for (String s2 : set2) {
String s3 = map2.get(s2);
System.out.println(s1 + "---" + s2 + "..." + s3);
}
}
System.out.println("++++++++++++");
for (String s1 : classStudy.keySet()) {
for (String s2 : classStudy.get(s1).keySet()) {
System.out.println(s1 + "---" + s2 + "..." + classStudy.get(s1).get(s2));
}
}
}
public static void get4(Map<String, Map<String, String>> classStudy){
Set<String> set1 = classStudy.keySet();
Iterator<String> it1 = set1.iterator();
while (it1.hasNext()) {
String s1 = it1.next();
Map<String, String> map2 = classStudy.get(s1);
Set<String> set2 = map2.keySet();
Iterator<String> it2 = set2.iterator();
while (it2.hasNext()) {
String s2 = it2.next();
String s3 = map2.get(s2);
System.out.println(s1 + "---" + s2 + "..." + s3);
}
}
}
}
|
|