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
• Devaka Cooray
• Ron McLeod
• Paul Clapham
• Liutauras Vilda
Sheriffs:
• paul wheaton
• Jeanne Boyarsky
• Tim Cooke
Saloon Keepers:
• Stephan van Hulst
• Tim Holloway
• Tim Moores
• Mikalai Zaikin
• Carey Brown
Bartenders:

# Sort list of dates from a specific given date

Ranch Hand
Posts: 324
• Number of slices to send:
Optional 'thank-you' note:

I need to find a way to Sort List from a specific date given as input. Let say the date given is Feb, I need to sort the list as [Feb, Apr, Jan]

Any clean way of doing this, do I need modify comparator.

Thanks,
Himalay

Sheriff
Posts: 14691
16
• Number of slices to send:
Optional 'thank-you' note:
If months were numbers (1 to 12), you could add +12 to any month below the month you are setting in priority. For example, let's say that Jan=1, Feb=2, ... Dec=12.
If you specify "sort from March", then Jan=Jan+12, Feb=Feb+12, Mar=3, ... Dec=12. So after sorting, Mar=3,...,Dec=12,Jan=13,Feb=14.

From there, you should figure out what to do with your comparator.

Himalay Majumdar
Ranch Hand
Posts: 324
• Number of slices to send:
Optional 'thank-you' note:
The format 'mmm' I mentioned for simplicity. Its actually 'mmm dd' so the list can have [Apr 16, Jan 21, May 05].
Can you please elaborate with some code, running on a short deadline.

Sheriff
Posts: 14691
16
• Number of slices to send:
Optional 'thank-you' note:

The format 'mmm' I mentioned for simplicity.

You see how simplicity could ruin everything. When you have a problem, you are supposed to explain what the problem is, not what a part of the problem is.

Anyway, the logic still holds:
Searching for Feb 12 (0212), add +1200 to anything before 0212.
Feb12(0212), Mar04(0304), Dec25(1225),Feb11(1411)

Javaranch is NotACodeMill, so I'd like you to come up with some code

 Oh the stink of it! Smell my tiny ad! a bit of art, as a gift, that will fit in a stocking https://gardener-gift.com