Sorting in Java
1 posts in topic
Flat View  Flat View

Posted By:   Titu_Prusty
Posted On:   Monday, February 16, 2004 05:33 AM

I have to sort a String array which cantains some elements.
Suppose ex :
A string array contains string like "Shyam","Ram","Shawn","Robbie".

How can i sort it.Is their any method in Collection classes where i can sort a string array or a Set.

Re: Sorting in Java

Posted By:   Prasanna_Talakanti  
Posted On:   Monday, February 16, 2004 01:51 PM

You can use sorted set, It follows the natural ordering of elments, The other way to do is to implement the Comparator Interface

//using sorted set
TreeSet t = new TreeSet();
SortedSet s = new TreeSet(t);
//if you want an array use toArray method in SortedSet

hope this helps
About | Sitemap | Contact