Advertisement
Guest User

Untitled

a guest
Apr 1st, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. class Score implements Comparable<Score> {
  4. int score;
  5. String name;
  6.  
  7. public Score(int score, String name) {
  8. this.score = score;
  9. this.name = name;
  10. }
  11.  
  12. @Override
  13. public int compareTo(Score o) {
  14. return score < o.score ? -1 : score > o.score ? 1 : 0;
  15. }
  16. }
  17.  
  18. public class Test {
  19.  
  20. public static void main(String[] args){
  21. List<Score> scores = new ArrayList<Score>();
  22.  
  23. scores.add(new Score(23, "Peter"));
  24. scores.add(new Score(11, "Tony"));
  25. scores.add(new Score(110, "Claire"));
  26. scores.add(new Score(13, "ferca"));
  27. scores.add(new Score(55, "Julian"));
  28. scores.add(new Score(13, "Pedro"));
  29.  
  30. Collections.sort(scores);
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement