5,781,349 members and growing! (85 online)
Email Password   helpLost your password?
General Programming » Algorithms & Recipes » Sorting     Beginner License: The Code Project Open License (CPOL)

Sorting the Objects in java

By Koundinya

This simple program helps the user how to sort objects
Java, Java, NT4, Win2K, Windows, Dev

Posted: 1 Nov 2001
Updated: 1 Nov 2001
Views: 53,177
Bookmarked: 6 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
16 votes for this Article.
Popularity: 3.23 Rating: 2.68 out of 5
5 votes, 55.6%
1
0 votes, 0.0%
2
1 vote, 11.1%
3
0 votes, 0.0%
4
3 votes, 33.3%
5
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

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Koundinya


Hi
I am from South India (Hyderabad). Basically I am lover of mathematics which made me to enter computer field. I started learning computer sciences with language B.B.C Basic.
Later I changed my track to C, C++ and Java.


Occupation: Web Developer
Location: India India

Other popular Algorithms & Recipes articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 1 of 1 (Total in Forum: 1) (Refresh)FirstPrevNext
GeneralJava Array sortingmembermsohan015:48 11 Nov '06  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 1 Nov 2001
Editor:
Copyright 2001 by Koundinya
Everything else Copyright © CodeProject, 1999-2009
Java | Advertise on the Code Project