Sort based on the 1st parameter(has more preference), if this is not available then sort based on the 2nd parameter.

Is it possible to code this logic?

February 17th, 2010, 02:26 PM

helloworld922

Re: Sorting an Array

Yes it is. Simply have your object implement the compareTo method, then implement that type of a comparison inside that method.

February 21st, 2010, 03:00 PM

mspray

Re: Sorting an Array

You can also use the sort(T[] a, Comparator<? super T> c) Sorts the specified array of objects according to the order induced by the specified comparator. I believe this will do what you want and it is simplified into one function call.