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 7503263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:09:34+00:00 2026-05-29T21:09:34+00:00

LinkedHashMap is used to preserve insertion order in the map, but this only works

  • 0

LinkedHashMap is used to preserve insertion order in the map, but this only works for mutable maps. Which is the immutable Map implementation that preserves insertion order?

  • 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-05-29T21:09:36+00:00Added an answer on May 29, 2026 at 9:09 pm

    ListMap implements an immutable map using a list-based data structure, and thus preserves insertion order.

    scala> import collection.immutable.ListMap
    import collection.immutable.ListMap
    
    scala> ListMap(1 -> 2) + (3 -> 4)
    res31: scala.collection.immutable.ListMap[Int,Int] = Map(1 -> 2, 3 -> 4)
    
    scala> res31 + (6 -> 9)
    res32: scala.collection.immutable.ListMap[Int,Int] = Map(1 -> 2, 3 -> 4, 6 -> 9)
    

    The following extension method – Seq#toListMap can be quite useful when working with ListMaps.

    scala> import scalaz._, Scalaz._, Liskov._
    import scalaz._
    import Scalaz._
    import Liskov._
    
    scala> :paste
    // Entering paste mode (ctrl-D to finish)
    
    implicit def seqW[A](xs: Seq[A]) = new SeqW(xs)
    class SeqW[A](xs: Seq[A]) {
      def toListMap[B, C](implicit ev: A <~< (B, C)): ListMap[B, C] = {
        ListMap(co[Seq, A, (B, C)](ev)(xs) : _*)  
      }
    }
    
    
    // Exiting paste mode, now interpreting.
    
    seqW: [A](xs: Seq[A])SeqW[A]
    defined class SeqW
    
    scala> Seq((2, 4), (11, 89)).toListMap
    res33: scala.collection.immutable.ListMap[Int,Int] = Map(2 -> 4, 11 -> 89)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have used LinkedHashMap because it is important the order in which keys entered
I'm using a LinkedHashMap as cache. I've overridden removeEldestEntry in order to force this
I know LinkedHashMap has a predictable iteration order (insertion order). Does the Set returned
I have LinkedHashMap returning from DB. From this map I need to get the
I have a map like this, Map<Integer,ArrayList<Object>> myMap = new LinkedHashMap<Integer,ArrayList<Object>>(); Now I have
How can you shrink a LinkedHashMap ? I overrode the removeEldestEntry method, but this
I know how to limit size in Map ( like this ,using LinkedHashMap.removeEldestEntry method
Possible Duplicate: Iterating through a LinkedHashMap in reverse order How to traverse Linked Hash
So i want to pass a LinkedHashMap to an intent. //SEND THE MAP Intent
Looking at the JDK source code for LinkedHashMap, I noticed that this class is

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.