Dart Map
Dart Map is very similar to Java Map.
Create Map
Create a map with initial elements.
Map<String, int> m = {'a': 1, 'b': 2};
Create an empty map.
Map<String, int> m = {};
// Or
var m = new Map<String, int>();
Add element
Add element to a map using [key]=
.
Map<String, int> m = {};
m['a'] = 1;
Check if key exists
Check if key exists in a map using containsKey
.
Map<String, int> m = {'a': 1, 'b': 2};
m.containsKey('a'); // true
You can also check if value exists in a map using containsValue
.