Created
September 14, 2023 17:49
-
-
Save rohanjai777/14b2be1d27dce104c86b4a0b2232edd9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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