• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Sorting List according to Date

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

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 =
altPremScheduleVector.iterator();
PremiumSchedule premiumSchedule = null;
while (altPremScheduleVectorIterator.hasNext()) {
premiumSchedule = new PremiumSchedule();
AltPremMode altPremMode = (AltPremMode) altPremScheduleVectorIterator.next();
premiumSchedule = populatePremiumSchedule(altPremMode);
date = premiumSchedule.getEffectiveDate();
System.out.println("Effective Date: "+date);
returnList.add(premiumSchedule);
}

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.

Thanks,
Kunal
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Kunal Sathe
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks John!

That seems to have worked!

Really appreciate the quick response.

Kunal
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic