I'm interested in an efficient way to store pairs of numbers, and to sort them according to a value of one of the numbers. Say I have a list of numbers:
(1, 2), (3, 5), (4, 3), (7, 8)
These pairs need to be stored in some way, then sorted in descending order of the second number, such that the order of these pairs is
(7, 8), (3, 5), (4, 3), (1, 2)
What would be the Java code to achieve this? I'm aware of C++'s std::pair
, but I was wondering about the procedure in Java.