Map Structures (Dictionary) in Dart

Baransel - Sep 29 '21 - - Dev Community

The map structure is one of the list types that allows us to keep more than one data. The most important features of
Map:

  • It works as key – value.
  • unordered

We can think of this structure as a dictionary. A word has only one meaning. Here too, word=key, meaning=value
corresponding to the word.

It is also important because we use the Map structure a lot when using a database. Below are examples of uses of the
map structure.

main() {
  Map<String, int> map1 = {'zero': 0, 'one': 1, 'two': 2};
  print(map1);

  Map map2 = {'zero': 0, 'I': 'one', 10: 'X'};
  print(map2);

  var map3 = {'zero': 0, 'I': 'one', 10: 'X'};
  print(map3);
}
Enter fullscreen mode Exit fullscreen mode

Output:

{zero: 0, one: 1, two: 2}
{zero: 0, I: one, 10: X}
{zero: 0, I: one, 10: X}
Enter fullscreen mode Exit fullscreen mode

 

main() {
  List<String> letters = ['I', 'V', 'X'];
  List<int> numbers = [1, 5, 10];

  Map<String, int> map = Map.fromIterables(letters, numbers);
  print(map);
}
Enter fullscreen mode Exit fullscreen mode

Output:

{I: 1, V: 5, X: 10}
Enter fullscreen mode Exit fullscreen mode

Follow my blog for more baransel.dev.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .