是的。
视频中毕老师也提到了。map是如何遍历的。
先转set,在通过迭代器获取。- TreeMap<Student,String> tm=new TreeMap<Student,String>(new StuNameComparator());
- tm.put(new Student("zhangsan",29),"shanghai");
- tm.put(new Student("zhangsan",20),"nanjing");
- tm.put(new Student("lisi",22),"beijing");
- tm.put(new Student("wangwu",23),"shanxi");
- tm.put(new Student("chenliu",25),"henan");
- Set<Map.Entry<Student,String>> entrySet=tm.entrySet(); //转成set
- Iterator<Map.Entry<Student,String>> it=entrySet.iterator();//通过遍历获得
复制代码 感觉Map.Entry<K,V>感觉好牛 |