metadeck
10/4/2018 - 2:40 PM

Beginners Dart - Maps

Beginners Dart - Maps

void main(){

  //Declaring the main, with functionality using lists and strings.
  //Map = Key Value Pair
  //Map people = {“dad : Norbert”,”mom : Bilinda”,”daughter : Lorise”, “son : Stevin”}
  //Declaring the map.

  //Declaring a map through lists.
  Map<String, String> people = new Map<String, String>();

  //Assigning the map data to the list.
  people.putIfAbsent("dad", () => "Norbert");
  people.putIfAbsent("son", () => "Stevin");
  people.putIfAbsent("daughter", () => "Lorise");
  people.putIfAbsent("mom", () => "Bilinda");

  //Print the list.
  print(people);
  //Print the keys.
  print ("Keys = ${people.keys}");
  //Print the values
  print ("Values = ${people.values}");
  //Print the value of the key defined as son.
  print ("The son is ${people["son"]}.");

}