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{ @

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/03 17:30:37
public class TreeMapDemo { public static void main(String[] args) {TreeMap tr=new TreeMap(new Mycomparator()); tr.put(

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{ @
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() 的作用在哪边?我把他删除了.照样可以输出这些数啊!求解

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{ @
比较器 多用来排序