Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Maps

  • map

  • hash

  • dictionary

  • associative array

  • Key/value pairs

  • Keys are unique and cannot be null

  • Access by key is O(1)

main() {
  Map joe = {
     "name"  : "Joe",
     "email" : "joe@somewhere.com" 
  };
  print(joe); // {name: Joe, email: joe@somewhere.com} 
  
  joe.putIfAbsent('email', () => 'a@b.com');
  print(joe); // {name: Joe, email: joe@somewhere.com}
  joe.putIfAbsent('birthdate', () => new DateTime.now());
  print(joe);
  // {name: Joe, email: joe@somewhere.com, birthdate: 2014-02-25 20:53:04.548}

  print(joe.containsKey('email')); // true
}