本帖最后由 刘建宇 于 2011-11-14 23:25 编辑
import java.util.*;
public class MapDome {
public static void Dome(){
Map<String,List<Student>>map=new HashMap<String,List<Student>>();
List<Student>list1=new ArrayList<Student>();
List<Student>list2=new ArrayList<Student>();
list1.add(new Student("zhangsan",123));
list1.add(new Student("lisi",124));
list2.add(new Student("wangwu",125));
list2.add(new Student("liliu",126));
map.put("一班", list1);
map.put("二班", list2);
Set<String>set=map.keySet();
Iterator<String> it=set.iterator();
while(it.hasNext()){
String s=it.next();
System.out.println(s);
List<Student>ist=map.get(s);
Iterator<Student>t=ist.iterator();
while(t.hasNext()){
Student stu=t.next();
System.out.println(stu);
}
}
}
public static void main(String args[]){
Dome();
}
}
class Student{
private String name;
private int id;
Student(String name,int id){
this.name=name;
this.id=id;
}
public String toString(){
return id+"..."+name;
}
}
|
|