Click here to Skip to main content
11,720,321 members (67,004 online)
Click here to Skip to main content

Sorting the Objects in Java

, 1 Nov 2001 CPOL 69K 11
Rate this:
Please Sign up or sign in to vote.
This simple program helps the user to sort objects.


The following program helps the programmer to sort objects. This is mainly for beginners. 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++) 
      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]); 
      System.out.println("\nIntegers sorted List ..."); 
       for(int i=0;i<in.length;i++) 
    public static List sort(Object o[]) 
                 ArrayList al=new ArrayList(); 
                for(int i=0;i<o.length;i++) 
                 List list = Collections.synchronizedList(al); 
                 return list; 


  • 1st November, 2001: Initial post


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


About the Author

Web Developer
India India
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.

You may also be interested in...

Comments and Discussions

GeneralJava Array sorting Pin
msohan0111-Nov-06 4:48
membermsohan0111-Nov-06 4:48 
The best way to sort array is to use Arrays class:

int ints[]={11,2,-22,401,6};Smile | :)
for(int i=0; i< ints.length; i++)
System.out.println("i=" + i + "-" + ints[i]);

Manish Sohaney

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150901.1 | Last Updated 2 Nov 2001
Article Copyright 2001 by Koundinya
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid