Assume that I have implemented a class Edge which has 4 attributes, all of which are of type int: from to quality length.
In my program , I have created an Edge[] array.
I want to Implement 2 Sorting Parameters -
One of them will sort the Edge array in descending order of the qualities,
The other will sort based on increasing order of lengths.
I will be needing these two orderings in distinct parts of my code.
I will be using the library function Arrays.sort() for sorting.
The only way I know of sorting Class Data Type Arrays to implement compareTo() within the class Edge but this only works for one parameter(quality or length but not both).
How can I implement two sorting functions(2 compareTo() functions ?) and decide which one to be called during sorting? In C++ , we can make many compare functions and simply state the function to go through.How to achieve this in Java?
Note: My goal is to sort an array of DataType Edge using Arrays.sort() , and use two different parameters for sorting and DECIDE which one is to be used at which point.