Results 1 to 4 of 4
  1. #1
    radhi16 is offline Member
    Join Date
    Jan 2011
    Posts
    30
    Rep Power
    0

    Default Arrange the given numbers of the array in descending order

    I have written the code for printing the numbers in ascending order using Arrays.sort().
    Can any one help me with descending order.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    You could create and use a Comparator object to sort the array in the opposite order. Have a look at the Comparator<T> API. Its use is similar to Comparable except that you need a compare method that takes two parameters rather than a compareTo method that takes one. If after you give it a try it doesn't work, come back with your code and any error messages and we'll likely be able to help you.

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,541
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by radhi16 View Post
    I have written the code for printing the numbers in ascending order using Arrays.sort().
    Can any one help me with descending order.
    If all you need is printing the elements in reverse order why don't you simply loop over the array backwards? Or reverse the array after sorting. Or do as Fubarable (see above) suggested.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  4. #4
    radhi16 is offline Member
    Join Date
    Jan 2011
    Posts
    30
    Rep Power
    0

Similar Threads

  1. Replies: 4
    Last Post: 01-01-2011, 10:52 AM
  2. [SOLVED] Sorting array in descending order?
    By dan0 in forum New To Java
    Replies: 14
    Last Post: 04-16-2009, 12:19 AM
  3. Sorting in descending order
    By santanu in forum New To Java
    Replies: 6
    Last Post: 11-26-2008, 11:43 PM
  4. Descending order
    By santanu in forum New To Java
    Replies: 1
    Last Post: 11-04-2008, 04:33 PM
  5. Display the data in Descending order
    By santanu in forum New To Java
    Replies: 2
    Last Post: 10-31-2008, 12:06 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •