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

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

问题描述

我的ArrayList。

I have an arrayList.

这是一个字符串的ArrayList。该字符串包含与Date.toString的格式为1970年1月1日,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)将它们排序,比较,但我建议你存储日期而不是字符串摆在首位,使排序更容易(日期农具可比<日期方式>

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>.

(如果你的输入格式为:字符串,然后转换字符串的时候将它们添加到列表)

(If your input format is String, then convert the Strings at the time you add them to the list)

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

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