Win a copy of Emmy in the Key of Code this week in the General Computing 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Sort list of dates from a specific given date

 
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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
 
Let's go to the waterfront with this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!