代码如下,本来是想先打印一个班级名,然后打印班级里的学生。是班级名,学生,班级名,学生的格式,但运行后打印的是班级名,班级名,学生,学生的格式,看了半天,感觉代码没什么问题啊,求高人指点。
import java.util.*;
class student
{ private String id;
private String name;
student(String id,String name)
{
this.name=name;
this.id=id;
}
public String toString()
{
return id+":"+name;
}
}
class MapTest2
{ public static void main(String[] args)
{ Demo();
}
public static void Demo()
{HashMap<String,List<student>> czbk=new HashMap<String,List<student>>();
List<student> yure=new ArrayList<student>();
List<student> jiuye=new ArrayList<student>();
czbk.put("yureban:",yure);
czbk.put("jiuyeban:",jiuye);
yure.add(new student("01","zhagnsan"));
yure.add(new student("02","liai"));
yure.add(new student("03","qNFQU"));
yure.add(new student("01","zhagnsan1"));
yure.add(new student("02","SUNSAN"));
yure.add(new student("03","ZHAOLIU"));
Iterator<String> it=czbk.keySet().iterator();
while(it.hasNext())
{ String roomname=it.next();
List<student> room=czbk.get(roomname);
System.out.println(roomname);
getStudent(room);
}
}
public static void getStudent(List<student> list )
{ Iterator<student> it=list.iterator();
while(it.hasNext())
{
student s=it.next();
System.out.println(s);
}
}
} |
|