Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9220013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:14:58+00:00 2026-06-18T03:14:58+00:00

I have a List of some tuples, one if this tuple contains a timestamp.

  • 0

I have a List of some tuples, one if this tuple contains a timestamp. I try to order this list by timestamp and convert to map, like:

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}")

but the output is wrong:

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

Does anyone have an idea what I am doing wrong? I expect timestamps to be in ascending order but they aren’t.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T03:14:59+00:00Added an answer on June 18, 2026 at 3:14 am

    Maps do not preserve order, so your sorting is thrown away again. You can use a SortedMap if it is essential that your map stay sorted. If you want a nonstandard ordering, you can specify one in a TreeMap.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list of tuples e.g. like this: l=[ (2,2,1), (2,4,0), (2,8,0), (4,2,0),
I have a list which contains some items of type string. List<string> lstOriginal; I
I have created a repeat control that list some documents. I would like to
Suppose I have a bulleted list like this: * list item 1 * list
So I have a list of tuples of two floats each. Each tuple represents
I have a list of tuples that contains a tool_id, a time, and a
In C#, I have a List<Tuple<DateTime,Double>> named timeseries. I'm trying to calculate some basic
I have a list of tuples where each tuple is a (start-time, end-time) .
I have a list of tuples. Every tuple has 5 elements (corresponding to 5
I have a list of some arbitrary objects, for the purpose of the example

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.