The syntax of Map.entries property is:
Iterable<MapEntry<K, V>> entries
This entries property of Map the map entries of this
.
Map.entries returns value of type Iterable<MapEntry<K, V>>
.
In this example,
map
with string keys and integer values.entries
property of the map, which returns an iterable of MapEntry
instances.void main() {
Map<String, int> map = {'apple': 1, 'banana': 2, 'cherry': 3};
Iterable<MapEntry<String, int>> mapEntries = map.entries;
print(mapEntries);
}
(MapEntry(apple: 1), MapEntry(banana: 2), MapEntry(cherry: 3))
In this example,
map
with integer keys and string values.entries
property of the map, which returns an iterable of MapEntry
instances.void main() {
Map<int, String> map = {1: 'a', 2: 'b', 3: 'c'};
Iterable<MapEntry<int, String>> mapEntries = map.entries;
print(mapEntries);
}
(MapEntry(1: a), MapEntry(2: b), MapEntry(3: c))
In this example,
map
with string keys and double values.entries
property of the map, which returns an iterable of MapEntry
instances.void main() {
Map<String, double> map = {'apple': 3.5, 'banana': 2.8, 'cherry': 4.1};
Iterable<MapEntry<String, double>> mapEntries = map.entries;
print(mapEntries);
}
(MapEntry(apple: 3.5), MapEntry(banana: 2.8), MapEntry(cherry: 4.1))
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.