Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Order ArrayList of dates in decending or ascending order

I have an array list of Dates and I want to order it by dates in ascending and descending order. Could anyone please provide a complete code snippet for this ? I have seen many questions like this but could not find a suitable answer.

List will be like this

         List<Date> dates= new ArrayList<Date>();

Any kind of help will be appreciated , Many thanks,

like image 745
Munazza Avatar asked Dec 01 '22 04:12

Munazza


1 Answers

Since Date already implements Comparable, you can simply use:

Collections.sort(dates);

to sort in ascending order, and for descending order:

Collections.sort(dates, Collections.reverseOrder());
like image 180
assylias Avatar answered Dec 02 '22 17:12

assylias