- class MapTest
- {
- public static void main(String[] args)
- {
- Map<Student,String> tm = new TreeMap<Student,String>();
- tm.put(new Student("blisi3",23),"nanjing");
- tm.put(new Student("lisi1",21),"beijing");
- tm.put(new Student("alisi4",24),"wuhan");
- tm.put(new Student("lisi1",21),"tianjin");
- tm.put(new Student("lisi2",22),"shanghai");
-
- Set<Map.Entry<Student,String>> entrySet = tm.entrySet();
- Iterator<Map.Entry<Student,String>> it = entrySet.iterator();
- while(it.hasNext())
- {
- Map.Entry<Student,String> me = it.next();
- Student stu = me.getKey();
- String addr = me.getValue();
- System.out.println(stu+":::"+addr);
- }
- }
- }
复制代码 |