我有一些元组的列表,如果这个元组包含时间戳。我尝试按时间戳排序此列表并转换为地图,例如:
println(s"--list before order ${vendingMachineResults.map(v => v._5.timestamp)}")
val vendingMachineResultsGroupedByTimestamp =
vendingMachineResults.sortBy(v1 =>
(new DateTime(v1._5.timestamp)).toDate()
).flatMap(vendingMachineResult =>
Map(vendingMachineResult._5.timestamp -> vendingMachineResult)
).toMap
println(s"--Map with vending machines ordered by timestamp: ${vendingMachineResultsGroupedByTimestamp.keys}")
但输出错误:
--List before ordering:
List(2012-04-16 14:33:34.807,
2012-02-16 14:52:25.715,
2012-06-18 14:52:25.715,
2012-07-10 14:54:19.651,
2012-07-16 14:54:19.651)
--Map with vending machines ordered by timestamp:
Set(2012-04-16 14:33:34.807,
2012-02-16 14:52:25.715,
2012-06-18 14:52:25.715,
2012-07-16 14:54:19.651,
2012-07-10 14:54:19.651)
有谁知道我做错了什么?我希望时间戳按升序排列,但事实并非如此。