本帖最后由 俊勇 于 2015-4-8 22:31 编辑
//创建对象
HashMap<String,TreeSet<Student>> czbk = new HashMap<String,TreeSet<Student>>();
//创建元素对象
TreeSet<Student> yr = new TreeSet<Student>();
yr.add(new Student("01","zhangsan"));
yr.add(new Student("02","lisi"));
TreeSet<Student> jy = new TreeSet<Student>();
jy.add(new Student("01","wangwu"));
jy.add(new Student("02","zhaoliu"));
//添加元素
czbk.put("yr", yr);
czbk.put("jy", jy);
//遍历
Set<String> czbkKeys = czbk.keySet();
for(String czbkKey:czbkKeys){
System.out.println(czbkKey);
TreeSet<Student> ts = czbk.get(czbkKey);
for(Student stu:ts){
System.out.println("\t"+stu.getName()+"***"+stu.getId());
}
} |
-
答案.jpg
(85.06 KB, 下载次数: 11)
答案
|