排序对数组

时间:2018-12-20 22:02:09

标签: java arrays sorting

我有一个“情侣”类,没有什么比字符串和双精度型更特殊的了:

public class Couple{

public String mot;
public double indice;

public Couple(){
    this.mot = "";
    this.indice = 0;
}

public Couple(String t, double q){
    this.mot = t;
    this.indice = q;
}
}

现在,假设我有一对Couple。 我想通过每个值的双精度对该数组进行排序。 例如:

排序前:

{(“ hi”,3),(“ hello”,1),(“ Good”,2),(“ nice”,0)}

根据每对夫妇的双精度值进行排序后:

{(“ nice”,0),(“ hello”,1),(“ Good”,2),(“ hi”,3)}

1 个答案:

答案 0 :(得分:0)

this.game用于情侣课程,覆盖implements Comparable,然后使用compareTo进行排序

Collections.sort();