Results 1 to 5 of 5

Thread: Sorting an Array in descending order{resolved}

  1. #1

    Thread Starter
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Sorting an Array in descending order{resolved}

    I know how to sort an array by using the Arrays.sort() method of the array class but that only sorts it in ascending order. How do you sort in descending order?
    Last edited by System_Error; Jun 10th, 2004 at 10:08 AM.

  2. #2
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    Since most of the sort() methods of the java.util.Arrays class sort there arguement in ascending order you probably will have to use the sort() method that take a Comparator as an arguement.

  3. #3

    Thread Starter
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111
    Could you please explain that a little better? Remember I'm a newbie at Java

  4. #4
    Fanatic Member TDQWERTY's Avatar
    Join Date
    Oct 2003
    Location
    Oporto & Leiria, Portugal / Luanda, Angola
    Posts
    972
    Simple, u just sort it ascending and then make a

    Code:
    public static void main(String[] args)
    	{
    	String xpto[] = {"01","02","03","04","05","06","07","08","09","10"};
    	for(int x=0;x<10;x++)
    		System.out.println(xpto[10 - 1 - x]);
    	}
    ::Winamp 5.xx id3v2 & modern skin support::
    ::NetCF DataGrid Programatically Scroll Example::
    Don't forget to rate posts from those who helped you solving your problem, clicking on and rating it.

  5. #5

    Thread Starter
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111
    Thanks for the help.

Posting Permissions

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



Click Here to Expand Forum to Full Width