This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes sorting a string array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "sorting a string array" Watch "sorting a string array" New topic
Author

sorting a string array

vidu mayur
Ranch Hand

Joined: Nov 13, 2003
Posts: 32
Hi guys
I am using a string array which has numbers in it. I want to sort the array by using insertion sort and storing the sorted numbers in a vector. When I used the following code, the program doesn't sort the numbers in the correct order. Where did I go wrong? Please help me.

Thanks
Vidu
chi Lin
Ranch Hand

Joined: Aug 24, 2001
Posts: 348
inside if clauses, try to convert those two strings into "int"
by using Integer.parseInt(String), then compare the numeric
value should give you the correct result

if (itemToInsert.compareTo( (String) v.elementAt(i)) < 0)
break;
}
vidu mayur
Ranch Hand

Joined: Nov 13, 2003
Posts: 32
It is working now. Thanks a lot!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: sorting a string array
 
Similar Threads
JFormattedTextField
Vector.size()
Comparator
Copying from Vector to Array: any inbuilt java method available like List.addAll(Vector)
need help with Bitset