Discuss / Java / compareTo() 方法

compareTo() 方法

Topic source

//按分数从小到大顺序排序  如果 分数 一样 按姓名字典顺序 排序

@Override
public int compareTo(Person other) {

int score = this.score - other.score;

if (score == 0) {
score = this.name.compareTo(other.name);
}

return score;
}

🌙

#2 Created at ... [Delete] [Delete and Lock User]

现在也不明白当时的脑回路是什么了.为什么要这样写.


  • 1

Reply