分享两种
Set<String> set1=map.keySet();
for(String key:set1)
{
Student s=map.get(key);
System.out.println("家族:"+key+",姓名:"+s.getName()+",年龄:"+s.getAge());
}
System.out.println("--------------------");
Set<Map.Entry<String,Student>> set2=map.entrySet();
for(Map.Entry<String,Student> str:set2)
{
String name=str.getKey();
Student stu=str.getValue();
System.out.println("家族:"+name+",姓名:"+stu.getName()+",年龄:"+stu.getAge());
} |