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,
- We create a map named
map
with string keys and integer values. - We access the
entries
property of the map, which returns an iterable ofMapEntry
instances. - We print the map entries to standard output.
Dart Program
void main() {
Map<String, int> map = {'apple': 1, 'banana': 2, 'cherry': 3};
Iterable<MapEntry<String, int>> 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,
- We create a map named
map
with integer keys and string values. - We access the
entries
property of the map, which returns an iterable ofMapEntry
instances. - We print the map entries to standard output.
Dart Program
void main() {
Map<int, String> map = {1: 'a', 2: 'b', 3: 'c'};
Iterable<MapEntry<int, String>> 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,
- We create a map named
map
with string keys and double values. - We access the
entries
property of the map, which returns an iterable ofMapEntry
instances. - We print the map entries to standard output.
Dart Program
void main() {
Map<String, double> map = {'apple': 3.5, 'banana': 2.8, 'cherry': 4.1};
Iterable<MapEntry<String, double>> 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.