Skip to content

Instantly share code, notes, and snippets.

@rohanjai777
Created September 14, 2023 17:49
Show Gist options
  • Save rohanjai777/14b2be1d27dce104c86b4a0b2232edd9 to your computer and use it in GitHub Desktop.
Save rohanjai777/14b2be1d27dce104c86b4a0b2232edd9 to your computer and use it in GitHub Desktop.
class Pair implements Comparable<Pair>{
String name;
int height;
public Pair(String name, int height){
this.name = name;
this.height = height;
}
public int compareTo(Pair other){
return other.height - this.height; //descending order => this.height - other.height for ascending order
}
}
Arrays.sort(ARRAY OF PAIR)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment