aspose file tools
The moose likes Beginning Java and the fly likes Sorting Array in Descending Order Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Sorting Array in Descending Order" Watch "Sorting Array in Descending Order" New topic
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
    
    4
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.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Sorting Array in Descending Order
 
Similar Threads
need help
array sorting
Need help in understanding how Comparable and Comparator works ?
Sort song titles
Just a simple for loop question