Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Sort list of dates from a specific given date

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


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
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
reply
    Bookmark Topic Watch Topic
  • New Topic