This page contains an archived post to the Java Answers Forum made prior to February 25, 2002.
If you wish to participate in discussions, please visit the new
Artima Forums.
Message:
names in ascending order
Posted by swapnil on November 16, 2000 at 9:47 AM
hi, sarish this program is very much general and u can use it for any no. of names u want to arrange in ascending order.just write the names in the command line as the arguments and u shall get the sorted list in the ascending order. The program goes like this : ............................................................... import java.util.*; public class ascending { public static void main(String[] args) { TreeSet ts=new TreeSet(); for(int i=0;i { ts.add(args[i]); } String myarr[]=new String[ts.size()]; Iterator myiter=ts.iterator(); int index=0; while(myiter.hasNext()) { myarr[index]=(String)myiter.next(); index=index+1; } System.out.println("The sorted names are :"); for (int i=0;i {System.out.println(myarr[i]); } } } ................................................................hope this too helps, regards, swapnil
Replies:
|