public class TreeMapDemo { public static void main(String[]

public class TreeMapDemo { public static void main(String[] args) {
TreeMap tr=new TreeMap(new Mycomparator()); tr.put("A", 12); tr.put("B", 13); tr.put("C", 14); tr.put("D", 15); System.out.println(tr); } } class Mycomparator implements Comparator{ @Override public int compare(Object o,Object oo) { String s1=(String)o; String s2=(String)oo; return s2.compareTo(s1); } } 我问下,这加入 new Mycomparator() 的作用在哪边?我把他删除了.照样可以输出这些数啊!求解
xhmtp 1年前 已收到1个回答 举报

王沙 花朵

共回答了19个问题采纳率:100% 举报

比较器 多用来排序

1年前

4
可能相似的问题
Copyright © 2024 YULUCN.COM - 雨露学习互助 - 16 q. 1.866 s. - webmaster@yulucn.com