File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

sorting a string array

 
vidu mayur
Ranch Hand
Posts: 32
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 348
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 32
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is working now. Thanks a lot!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic