long firstNum;
long secondNum;
。。。。
。。。。
。。。。
public int compareTo(MyNewKey anotherKey) {
long min = firstNum - anotherKey.firstNum;
if (min != 0) {
// 说明第一列不相等,则返回两数之间小的数
return (int) min;
} else {
return (int) (secondNum - anotherKey.secondNum);
}
}
compareTo提供排序的比较依据,这里,先按照第一个数排序,第一个数如果相同,再按照第二个数排序。