本帖最后由 尖卡斌引 于 2013-5-16 21:53 编辑
/*
演示示例:
传智播客有N多班级,
每个班级有N多学生。
利用Map集合建立 并打印所有学生的 id 和name。
*/
import java.util.*;
class Student
{
private String id;
private String name;
Student(String id,String name)
{
this.id = id;
this.name = name;
}
public String toString()
{
return id+"............"+name;
}
}
class MapDemo2
{
public static void main(String[] args)
{
HashMap<String,List<Student>> czbk = new HashMap<String,List<Student>>();
List<Student> yure = new ArrayList<Student>();
List<Student> jiuye = new ArrayList<Student>();
yure.add(new Student("y------001","zhangsan"));
yure.add(new Student("y------003","lisi"));
yure.add(new Student("y------004","wangwu"));
yure.add(new Student("y------002","xueliu"));
jiuye.add(new Student("j---=======---002","wangwu2"));
jiuye.add(new Student("j---=======---004","wangwu4"));
jiuye.add(new Student("j---=======---003","wangwu3"));
jiuye.add(new Student("j---=======---001","wangwu1"));
Iterator<String> it = czbk.keySet().iterator();
while(it.hasNext())
{
String roomName = it.next();
List<Student> room = czbk.get(roomName);
System.out.println(roomName);
getInfos(room);
}
}
public static void getInfos(List<Student> list)
{
Iterator<Student> it = list.iterator();
while(it.hasNext())
{
Student s = it.next();
System.out.println(s);
}
}
}
编译 运行都没有错误,就是没有结果。 高手指点 |