我有一些元組列表,其中一個元組包含時間戳。我試圖通過時間戳排序此列表,並轉換成地圖,如:在地圖中排序時間戳
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)
有沒有人有一個想法是什麼,我做錯了什麼?我希望時間戳按升序排列,但不是。