package com.Test.Demo.Test;
import java.util.Arrays;
import java.util.Comparator;
public class SortTest {
public static void main(String[] args){
Ren1[] r1={new Ren1(123,"qwe"),new Ren1(99,"uio"),new Ren1(150,"tuu")};
Arrays.sort(r1,new bi());
for(Ren1 t:r1){
System.out.println(t);
}
}
}
class bi implements Comparator<Ren1>{
@Override
public int compare(Ren1 o1, Ren1 o2) {
return o2.getScore()-o1.getScore();
}
}
class Ren1 implements Comparable<Ren1> {
private int score;
private String name;
public Ren1(int score, String name) {
this.score = score;
this.name = name;
}
public int getScore() {
return score;
}
public String getName() {
return name;
}
@Override
public String toString() {
return "Ren1{" +
"score=" + score +
", name='" + name + '\'' +
'}';
}
@Override
public int compareTo(Ren1 o) {
return o.getScore()-this.getScore();
}
}