0

I have a list of objects that I want to sort according to their "date" attribute. Each object has a Date attribute which specifies its age. How can I sort these objects from the newest to the oldest? I heard of Comparator but I don't know if it applies to dates.

Can somebody help me figure out how to do that?

NissimL
  • 148
  • 8
Hubert Solecki
  • 2,529
  • 5
  • 29
  • 58

2 Answers2

0

You can use the various methods of before(), after(), compareTo(), or convert the value into a Long and then compare that instead.

http://docs.oracle.com/javase/6/docs/api/java/util/Date.html

David Tran
  • 16
  • 2
0

You can convert date into timestamp and sort it. It is very easy for sorting.

Prashant Gurav
  • 505
  • 6
  • 17