黑马程序员技术交流社区
标题:
HashMap的嵌套
[打印本页]
作者:
gss
时间:
2015-9-30 21:19
标题:
HashMap的嵌套
package map;
import java.util.HashMap;
import java.util.Map;
import bean.Student;
public class Test6 {
public static void main(String[] args) {
HashMap<Student, String> hm = new HashMap<Student, String>();
hm.put(new Student("张三", 23), "北京");
hm.put(new Student("李四", 24), "上海");
hm.put(new Student("王五", 25), "韩国");
hm.put(new Student("周六", 26), "法国");
HashMap<Student, String> hm1 = new HashMap<Student, String>();
hm1.put(new Student("高芹", 22), "山东");
hm1.put(new Student("高博", 24), "上海");
hm1.put(new Student("高飞", 22), "日本");
hm1.put(new Student("豆豆", 20), "意大利");
HashMap<HashMap<Student, String>, String> list = new HashMap<>();
list.put(hm, "第一期");
list.put(hm1, "第二期");
// System.out.println(list);
for (HashMap<Student, String> s : list.keySet()) {
String value = list.get(s);
for (Student ss : s.keySet()) {
String value2 = s.get(ss);
System.out.println(ss + "=" + value2 + "=" + value);
}
}
}
}
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2