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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T02:30:43+00:00 2026-06-19T02:30:43+00:00

Dart has a Map type, with implementations like HashMap , LinkedHashMap , and SplayTreeMap

  • 0

Dart has a Map type, with implementations like HashMap, LinkedHashMap, and SplayTreeMap. What’s the difference between those different Map implementations?

  • 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-19T02:30:44+00:00Added an answer on June 19, 2026 at 2:30 am

    Dart has built-in support for collections like List, Set, and Map. Dart has different Map implementations. Understanding the pros and cons between implementations can help you make an informed decision.

    (Note: this is written around the time of Dart M3, so what follows might not match the docs at this moment.)

    What is a Map?

    A Map is an associative container, mapping keys to values. Keys are unique, and can point to one and only one value. A key cannot be null, but a value can be null.

    Map Literals

    Dart supports Map literals, like this:

    var accounts = {'323525': 'John Smith', '588982': 'Alice Jones'};
    

    The spec says that map literals must maintain insertion order. This means that accounts is an instance of LinkedHashMap.

    The spec also says that Map literal keys must be Strings. This might be changed in the future.

    new Map()

    Dart supports factory constructors, so you can create a new instance of Map like this:

    var accounts = new Map();
    

    The Map class is abstract, which means the factory constructor actually creates an instance of a subclass of Map. So what is the actual type of accounts ?

    Earlier versions of Dart created a new instance of HashMap from the new Map() constructor. However, Dart bug 5803 states that in order to make {} and new Map return the same type, new Map will soon return an instance of LinkedHashMap.

    LinkedHashMap (or, InsertionOrderedMap)

    A LinkedHashMap iterates through keys and values in the same order they were inserted.

    Note: LinkedHashMap will probably be renamed to InsertionOrderedMap. Follow Dart bug 2349 for progress.

    Here is an example:

    import 'dart:collection';
    main() {
      var ordered = new LinkedHashMap();
      ordered['32352'] = 'Alice';
      ordered['95594'] = 'Bob';
    
      for (var key in ordered.keys) {
        print(key);
      }
    
      // guaranteed to print 32352, then 95594
    }
    

    Here is the source code for LinkedHashMap. (if this link stops working, it’s probably because the class was renamed)

    HashMap

    A HashMap has no guarantee of maintaining insertion order. When you iterate through a HashMap’s keys or values, you cannot expect a certain order.

    A HashMap is implemented using a hash table.

    Here is an example of creating a new HashMap:

    import 'dart:collection';
    main() {
      var accounts = new HashMap();
    }
    

    If you don’t care about maintaining insertion order, use HashMap.

    Here is the source code of HashMap.

    SplayTreeMap

    A splay tree is a self-balancing binary search tree with the additional property that recently accessed elements are quick to access again. It performs basic operations such as insertion, look-up and removal in O(log(n)) amortized time.

    import 'dart:collection';
    main() {
      var accounts = new SplayTreeMap();
    }
    

    A SplayTreeMap requires that all keys are of the same type.

    A splay tree is a good choice for data that is stored and accessed frequently, like caches. The reason is that they use tree rotations to bring up an element to the root for better frequent accesses. The performance comes from the self-optimization of the tree. That is, frequently accessed elements are moved nearer to the top. If however, the tree is equally often accessed all around, then there’s little point of using a splay tree map.

    An example case is a modem router that receives network packets at very high rates. The modem has to decide which packet go in which wire. It can use a map implementation where the key is the IP and the value is the destination. A splay tree map is a good choice for this scenario, because most IP addresses will be used more than once and therefore those can be found from the root of the tree.

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

Sidebar

Related Questions

I am experimenting with Dart. I have created an on click event like so:
It looks like Google's Dart language doesn't allow you to call native js functions
Taken from the sample in mongo_dart's blog.dart I'd like to ad some strong typing
I understand that Dart has just been released, and while it's not entirely stable
Given something like: import 'dart:math'; I can't seem to find a way to get
I'm trying to load a dart script dynamically using dart. I'm using something like
Does server side Dart support sessions like in PHP: <?php session_start(); $_SESSION['fruit'] = 'apple';
Some languages like Dart use mirror based reflection so, in simple terms, what is
Dart has the concept of compile-time constants. A compile-time constant is parsed and created
Dart has a concept of final . Most dynamic languages don't have this concept.

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.