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

  • SEARCH
  • Home
  • 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 7966857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:32:43+00:00 2026-06-04T06:32:43+00:00

When I create an immutable map with a standard call to Map() or by

  • 0

When I create an immutable map with a standard call to Map() or by concatenating the existing maps created that way, in all my tests I get that traversing its members provides them in the order of addition. That’s exactly the way I need them to be sorted, but there’s not a word in the documentation about the reliability of the ordering of the members of the map.

So I was wondering whether it is safe to expect the standard Map to return its items in the order of addition or I should look for some other implementations and which ones in that case.

  • 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-04T06:32:45+00:00Added an answer on June 4, 2026 at 6:32 am

    I don’t think it’s safe, the order is not preserved starting from 5 elements (Scala 2.9.1):

    scala> Map(1 -> 1, 2 -> 2, 3 -> 3, 4 -> 4, 5 -> 5)
    res9: scala.collection.immutable.Map[Int,Int] = 
      Map(5 -> 5, 1 -> 1, 2 -> 2, 3 -> 3, 4 -> 4)
    

    With bigger maps the order is completely “random”, try Map((1 to 100) zip (1 to 100): _*).

    Try LinkedHashMap for ordered entries and TreeMap to achieve sorted entries.

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

Sidebar

Related Questions

How to create sorted map in scala (mutable/immutable)?
What is an elegant way to create and initialise instances of a class that
When I create a small Map in the repl, it tells me that its
What is the best way to create a Map[K,V] from a Set[K] and function
Is there a simple way to create an immutable NumPy array? If one has
I'm tying to write a class that will create immutable copies of another class,
Strings are immutable, meaning, once they have been created they cannot be changed. So,
Create a new appdomain, setup the assemblyResolve handler and you always get an exception
Create Pex test to test a DLL and hardware controlled by that DLL? I
I'm have a map that looks like this: Map[ A -> Collection[B]] . This

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.