Map

Anonymous contributor's avatar
Anonymous contributor
Anonymous contributor's avatar
Anonymous contributor
Published Feb 23, 2024
Contribute to Docs

The Map object is a key/value pair. The values and keys in a map may be of any type. A Map is a dynamic collection that can grow and shrink at runtime.

Syntax

The syntax to declare a map is:

var identifier = new Map()

Example

Here is an example of how to use map in Dart:

void main() {
var details = {'Cat':'jeff','Color':'brown'};
print(details);
}

The above code gives the following output:

{Cat: jeff, Color: brown}

Map

.clear()
Removes all the elements from a map.
.containsKey()
Checks if a particular key is present in a Map object.
.keys
Returns an iterable collection containing all the keys in a map.
.length
Retrieves the number of key-value pairs in a Map.
.putIfAbsent()
Inserts a key-value pair into a map if the key is not already present.

All contributors

Looking to contribute?

Learn Dart on Codecademy