This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes Sorting Arrays Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Sorting Arrays" Watch "Sorting Arrays" New topic
Author

Sorting Arrays

Zak Tacc
Greenhorn

Joined: Feb 01, 2010
Posts: 25
I'm using the following code to sort a single dimensional array of strings, but any time it encounters a number, the sort resets itself. What is wrong with my code?



After sorting, the array becomes something like this:

apple
bun
cactus
elephant
zebra
13
android
babylon
zen
4
andy
band

and so on and so forth. Thanks



pete reisinger
Ranch Hand

Joined: Dec 30, 2009
Posts: 46
Hi, you should use collection - they do the sorting for you (if they are sorted).
Check sorted set, sorted map etc.
collections
pete reisinger
Ranch Hand

Joined: Dec 30, 2009
Posts: 46
I just checked your code and it outputs this:
13
4
android
andy
apple
babylon
band
bun
cactus
elephant
zebra
zen
The only thing I changed is method signature:
public static String[] selectionSort(String[] data) {

then of course I added return data; at the end.

If I output the array:
selectionSort(data);
for(String x : data) {
System.out.println(x);
}

it outputs the above result
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Sorting Arrays