File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Sort ArrayList

 
Shrawan Bhageria
Ranch Hand
Posts: 52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

How we sort ArrayList.
If we sorre 20 car object in a ArrayList and we want to sort care object according to speed.How we can do that.

Regards,

Shrawan
 
Keith Lynn
Ranch Hand
Posts: 2399
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you checked out the API for the Collections class? There are some useful methods there.
 
Joanne Neal
Rancher
Pie
Posts: 3742
16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use Collections.sort() to sort an ArrayList.
You will either need your class to implement the Comparable interface and provide a suitable compareTo method, or you will need to create a Comparator class that implements a suitable compare method and pass this to the Collections.sort() method.

See the Java sorting tutorial and the API doc for each of the classes for more details.
[ September 28, 2006: Message edited by: Joanne Neal ]
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic