aspose file tools
The moose likes Java in General and the fly likes Sorting List according to Date Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Sorting List according to Date" Watch "Sorting List according to Date" New topic

Sorting List according to Date

Kunal Sathe
Ranch Hand

Joined: Apr 08, 2005
Posts: 49

I have a list of Objects. These objects contain the effective date. I want to sort this list of objects and reorder it according to the date. The following is the piece of code I am referring to:

public List getPremiumSchedulesList() {

List returnList = new ArrayList();
Date date = null;

Vector altPremScheduleVector = getAltPremScheduleVector();
Iterator altPremScheduleVectorIterator =
PremiumSchedule premiumSchedule = null;
while (altPremScheduleVectorIterator.hasNext()) {
premiumSchedule = new PremiumSchedule();
AltPremMode altPremMode = (AltPremMode);
premiumSchedule = populatePremiumSchedule(altPremMode);
date = premiumSchedule.getEffectiveDate();
System.out.println("Effective Date: "+date);

return returnList;


The premiumSchedule object contains an effective date. I want to sort this list according to the effective date. I would really apprecite if someone can point me in the right direction

Looking forward to your responses.

Deepak Bala

Joined: Feb 24, 2006
Posts: 6662

Have a look at the Comparator and Comparable interface. You can implement the "compare" function for your class and use one of the overloaded Collections.sort() method

SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Kunal Sathe
Ranch Hand

Joined: Apr 08, 2005
Posts: 49
Thanks John!

That seems to have worked!

Really appreciate the quick response.

Don't get me started about those stupid light bulbs.
subject: Sorting List according to Date