阅读(3395) (1)

Comparable

2019-06-26 20:22:22 更新

Comparable 从小到大排序(即:this,o)所需Comparable示例:

class A implements Comparable<A>{
    public int n;
    @Override
        public int compareTo(A o) {
        // TODO Auto-generated method stub
        if (this.n > o.n) {
            return 1;
        } else if(this.n == o.n) {
            return 0;
        } else {
            return -1;
        }
    }
}