Dart Map entries
Syntax & Examples

Syntax of Map.entries

The syntax of Map.entries property is:

 Iterable<MapEntry<K, V>> entries 

This entries property of Map the map entries of this.

Return Type

Map.entries returns value of type Iterable<MapEntry<K, V>>.



✐ Examples

1 Retrieve map entries of a map with string keys and integer values

In this example,

  1. We create a map named map with string keys and integer values.
  2. We access the entries property of the map, which returns an iterable of MapEntry instances.
  3. We print the map entries to standard output.

Dart Program

void main() {
  Map&lt;String, int&gt; map = {'apple': 1, 'banana': 2, 'cherry': 3};
  Iterable&lt;MapEntry&lt;String, int&gt;&gt; mapEntries = map.entries;
  print(mapEntries);
}

Output

(MapEntry(apple: 1), MapEntry(banana: 2), MapEntry(cherry: 3))

2 Retrieve map entries of a map with integer keys and string values

In this example,

  1. We create a map named map with integer keys and string values.
  2. We access the entries property of the map, which returns an iterable of MapEntry instances.
  3. We print the map entries to standard output.

Dart Program

void main() {
  Map&lt;int, String&gt; map = {1: 'a', 2: 'b', 3: 'c'};
  Iterable&lt;MapEntry&lt;int, String&gt;&gt; mapEntries = map.entries;
  print(mapEntries);
}

Output

(MapEntry(1: a), MapEntry(2: b), MapEntry(3: c))

3 Retrieve map entries of a map with string keys and double values

In this example,

  1. We create a map named map with string keys and double values.
  2. We access the entries property of the map, which returns an iterable of MapEntry instances.
  3. We print the map entries to standard output.

Dart Program

void main() {
  Map&lt;String, double&gt; map = {'apple': 3.5, 'banana': 2.8, 'cherry': 4.1};
  Iterable&lt;MapEntry&lt;String, double&gt;&gt; mapEntries = map.entries;
  print(mapEntries);
}

Output

(MapEntry(apple: 3.5), MapEntry(banana: 2.8), MapEntry(cherry: 4.1))

Summary

In this Dart tutorial, we learned about entries property of Map: the syntax and few working examples with output and detailed explanation for each example.