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,
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());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With