my dog learned polymorphism
The moose likes Java in General and the fly likes sorting collection of  objects by object members Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "sorting collection of  objects by object members" Watch "sorting collection of  objects by object members" New topic
Author

sorting collection of objects by object members

venkatesh loganathan
Greenhorn

Joined: Aug 24, 2004
Posts: 14
Hi all
I have to sort a collection of objects based onthe object property.If the object has firstname as a member then sortg should be based on that.Any hep regarding this.

Venkatesh Loganthan.
Pete Harris
Ranch Hand

Joined: Feb 05, 2003
Posts: 39
Venkatesh,

The answer here is to write a Comparator which will allow you to specify the sorting algorithm you want to use for your collection.

The only thing to mention is that you should read the javadoc and implement your class with care otherwise your sort could return odd results.

cheers, Pete
[ September 01, 2004: Message edited by: Pete Harris ]
Rickard Sundin
Greenhorn

Joined: Mar 10, 2003
Posts: 16
You may also want to look in on the sort methods provided by java.util.Collections (http://java.sun.com/j2se/1.4.2/docs/api/java/util/Collections.html).

/Rickard
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: sorting collection of objects by object members
 
Similar Threads
Sorting Collection of objects by object members
object
How To Get Rid Of java.util.ConcurrentModificationException?
Sorting using Comparable interface
duplicate/unique value count generics list