Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

sorting Java arrays & picking out largest/smallest

807600Nov 12 2007 — edited Nov 12 2007
hi all. I need to be able to sort a java array by ascending or preferably descending order. Once I have done this I need to be able to use the largest and smallest numbers (for example subtract the smallest number from the largest number in the array).

Please use the following array as an example in your responses. Obviously with the code now it will sort it in ascending order, but I do not know how to write code to do the sum 4 - -23.
int[] intArray = new int[] {4, 1, 3, -23};
    Arrays.sort(intArray);
    // [-23, 1, 3, 4]
P.S. how do I make the array descending as well?

thanks,
Jon
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 10 2007
Added on Nov 12 2007
1 comment
299 views