【发布时间】:2021-02-26 17:18:24
【问题描述】:
我需要从最早到最晚对 DateTime 列表进行排序。
List<DateTime> list = [2021-01-15 12:26:40.709246, 2021-02-25 13:26:40.709246, 2021-02-20 19:26:40.709246];
datetimeList.sort();
我还有另一个字符串列表。
List<String> list = ["one", "two", "three"];
stringList 的索引必须与 datetimeList 的索引匹配。所以“一”的索引必须始终与 2021-01-15 12:26:40.709246 的索引相同。
如果我单独对列表进行排序,则 DateTime 按 DateTime 排序,而 Strings 按字母顺序排序。这样一来,字符串就不再使用它的初始日期了。
如何对一个列表 (datetimeList) 进行排序,而另一个列表 (stringList) 的排序方式完全相同?
【问题讨论】: