关于interface Comparator??
我想通过用一个类实现Comparator接口,覆写其中的compare(),来改变Array.sort对int的排序方式(改成从大到小排) 可编译器提示
在 Arrays.sort(n,new intSort());出错
错误信息:method sort(int[],p_learn.IntSort) not found in class java.util.Arrays....
为什么?
下面是code:
----------------------------------------------------------------
package p_learn;
import java.util.*;
class IntSort implements Comparator{
public int compare(Object o1,Object o2){
Integer i1 = (Integer)o1;
Integer i2 = (Integer)o2;
return i1.compareTo(i2)> 0 ? -1 : (i1.compareTo(i2) == 0) ? 0 : 1;
}
}
public class Array2 {
public Array2() {}
public static void main(String[] args)
{
int [] n ={2,6,3,2,6};
Arrays.sort(n,new IntSort());
}