Map

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.
.containsValue()
Checks if a particular value is present in a map.
.forEach()
Iterates over each key-value pair in a map and applies a specified function to each pair.
.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.
.remove()
Removes the specified key and its associated value from a map.
.values
Returns an iterable object containing all the values in a specified Map.

All contributors

Contribute to Docs

Learn Dart on Codecademy