| Author |
Sorting Array in Descending Order
|
ShaikSalam Bashoeb
Greenhorn
Joined: Dec 10, 2008
Posts: 24
|
|
I know how to sort arrays in ascending order by using API's sort method, I want to know how to sort arrays in descending order by using API's method. For your information, i want to mention that i know how to sort arrays in descending order through manually. Any suggestions will be appreciated. Thanks in Advanced.........
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32712
|
|
Create a Comparator which returns negative numbers for "greater" and positive numbers for "smaller." Sort in the usual fashion and reverse the array.
|
 |
Paul Beckett
Ranch Hand
Joined: Jun 14, 2008
Posts: 95
|
|
have a look at the reverseOrder() and reverseOrder(Comparator) methods on the Collections class. They allow you to create a reverse order comparator based upon either the natural order of the objects or the supplied comparator depending upon which you choose. Have a look at the Collections java docs for more info.
|
 |
 |
|
|
subject: Sorting Array in Descending Order
|
|
|