class MapTest2
{
public static void main(String[] args)
{
TreeMap<Student,String>tm = new TreeMap<Student,String>(new StuNameComparator());
tm.put(new Student("zsi1",25),"beijing");
tm.put(new Student("wisi1",21),"ng");
tm.put(new Student("sisi2",28),"jing");
tm.put(new Student("aisi3",29),"bei");
tm.put(new Student("aisi3",29),"shangg");//相同了,判断全部一样,就替代原有的value
tm.put(new Student("csi4",24),"beng");
Set<Map.Entry<Student,String>>entry=tm.entrySet();
Iterator<Map.Entry<Student,String>>it=entry.iterator();
while (it.hasNext())
{
Map.Entry<Student,String>me=it.next();
Student stu=me.getKey();
String addr=me.getValue();
System.out.println(stu+";"+addr);
}
}
}
怎么改遍历器改成for循环啊,高手指点 |
|