更新时间:2023-01-30 10:19:26
您可以编写一个比较器来解析日期并使用 date.compareTo(otherDate)
,但我建议你首先存储 dates
而不是 Strings
,这样排序更容易(Date 实现 Comparable
.
You could write a comparator that parses the dates and sorts them using date.compareTo(otherDate)
, but I'd suggest you store dates
instead of Strings
in the first place, making sorting much easier (Date implements Comparable<Date>
.
(如果您的输入格式是String
,则在将它们添加到列表时转换Strings
)
(If your input format is String
, then convert the Strings
at the time you add them to the list)