How to get the earliest date of a List in Java?

mffm :

I have an ArrayList which stores 0...4 Dates.

The amount of Dates in the list depends on a Business logic.

How can I get the earliest date of this list? Of course I can build iterative loops to finally retrieve the earliest date. But is there a 'cleaner'/ quicker way of doing this, especially when considering that this list can grow on a later perspective?

Andy Turner :

java.util.Date implements Comparable<Date>, so you can simply use:

Date minDate = Collections.min(listOfDates);

This relies on there being at least one element in the list.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=453977&siteId=1
Recommended