按日期排序特殊字符串的数组列表 [英] sort array list of special strings, by date

查看:28
本文介绍了按日期排序特殊字符串的数组列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数组列表.

这是一个字符串数组列表.该字符串包含一个 "Date.toString",格式为 "January 1, 1970, 00:00:00 GMT" + 任务名称.

This is an arrayList of strings. The string contains a "Date.toString" in format of "January 1, 1970, 00:00:00 GMT" + task name.

例如:

"January 1, 1970, 00:00:00 GMT clean the house".

我想按日期对这个 arrayList 进行排序.
我该怎么做?

I want to sort this arrayList by dates.
How can I do it?

推荐答案

可以编写一个比较器来解析日期并使用 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)

这篇关于按日期排序特殊字符串的数组列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆