aspose file tools
The moose likes Beginning Java and the fly likes Sort contents of elements of ArrayList Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Sort contents of elements of ArrayList" Watch "Sort contents of elements of ArrayList" New topic
Author

Sort contents of elements of ArrayList

Shailesh Pillai
Ranch Hand

Joined: Jan 24, 2006
Posts: 78
Hello Ranchers,

How to sort an ArrayList based on the contents of its elements?

For instance this is myArrayList,


After the arraylist is populated, i would like the arraylist to be displayed in a sorted form i.e. based on the empName (ascending or descending).

Is there any way to achieve this......

Please help.

Thanks in advance.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Search the Java SE Javadoc for the method sort in the class java.util.Collections. That should get you started. Let us know if you have questions.

Also, please try to post to the appropriate forum. This is a basic java question, not a Struts question. I'm moving it to the Basic Java forum for you.


Merrill
Consultant, Sima Solutions
 
I agree. Here's the link: http://jrebel.com/download
 
subject: Sort contents of elements of ArrayList
 
Similar Threads
How to read the value selected in the selectOneMenu tag in the forwarded jsp page
Need Help:How to port HashMap<String-ColmnName, ArayList-ClumnData> to Datatable for multiple colmns
Problem: ArrayList with For loop
unsafe operation??
HibernateException: JDBC Driver class not found: oracle.jdbc.driver.OracleDriver