https://blog.csdn.net/u012250875/article/details/55126531

 

 

Integer中方法compare和compareTo的区别

    //compareTo
    public int compareTo(Integer anotherInteger) {
        return compare(this.value, anotherInteger.value);
    }

    //compare
    public static int compare(int x, int y) {
        return (x < y) ? -1 : ((x == y) ? 0 : 1);
    }

这就很清楚了,compare是静态的,可以通过类名直接调用.Integer.compare(a,b) 
compareTo是非静态的,只能通过对象名.compareTo()来调用

compareTo内部其实也是直接调用的compare方法. 
对象大于目标参数,返回1 
对象小于目标参数,返回-1 
对象等于目标参数,返回0