Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Sort contents of elements of ArrayList  RSS feed

 
Shailesh Pillai
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!