aspose file tools
The moose likes Beginning Java and the fly likes how do you sort the array into ascending orde Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "how do you sort the array into ascending orde" Watch "how do you sort the array into ascending orde" New topic
Author

how do you sort the array into ascending orde

nalamati satyanarayana
Ranch Hand

Joined: Dec 16, 2005
Posts: 36
public class SortSample {
public void printSorted(int arrayToSort[]) {

.. // Insert code to sort the array here

System.out.print("Sorted array is ");
for (int j = 0; j < arrayToSort.length; j++)
System.out.print(arrayToSort[j] + " ");
System.out.println();
}
Question In the above code, with the minimum of coding, how do you sort the array into ascending order?
Choice 1
Call java.util.Arrays.sort(arrayToSort).
Choice 2
Load the array values into a SortedList collection, then unload them back into the array in order.
Choice 3
Call java.util.Collections.sort(ArrayToSort).
Choice 4
Write a Shell-Metzner sort routine since we do not know the length of the array.
Choice 5
Write a bubble sort routine.
Svend Rost
Ranch Hand

Joined: Oct 23, 2002
Posts: 904
I'll tel you how to solve your problem...

Its actually easy.. find out what 1,2,3,4 and 5 does - and you have the
answer. The answers for 1,2 and 3can be found in the Java API and 4 and 5
can be found in a introductory book on algorithms (or using google).

/Svend Rost
[ March 07, 2007: Message edited by: Svend Rost ]
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14672
    
  11

I'm wondering why he's only posting exam questions without even telling what his doubt is... I don't think the ranch is an answering machine


[My Blog]
All roads lead to JavaRanch
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how do you sort the array into ascending orde
 
Similar Threads
need help
Sorting a row in a two deminsional array
arrays?
String Input and Bubble Sort
sorting an array of integers - a problem.