Note: This is an unedited contribution. If this article is inappropriate,
needs attention or copies someone else's work without reference then please
Report This Article
Introduction
The following program helps the programer to sort objects .This is mainly for the beginers and
i have used some collections classes to sort objects
public class
SortObjects
{
public static void main(String s[])
{
Collections col;
List l=sort(s);
System.out.println("\nStrings sorted List
...");
for(int i=0;i<s.length;i++)
{
System.out.println((String)l.get(i));
}
int ints[]={11,2,-22,401,6};
Integer in[]=new Integer[ints.length];
for(int i=0;i<in.length;i++)
{
in[i]=new
Integer(ints[i]);
}
l=sort(in);
System.out.println("\nIntegers sorted List
...");
for(int
i=0;i<in.length;i++)
{
System.out.println((Integer)l.get(i));
}
}
public static List sort(Object o[])
{
ArrayList
al=new ArrayList();
for(int
i=0;i<o.length;i++)
al.add(i,o[i]);
List list
= Collections.synchronizedList(al);
Collections.sort(list);
return
list;
}
}
Koundinya