Skip to content

Instantly share code, notes, and snippets.

@tailorvj
Created March 25, 2020 12:37
Show Gist options
  • Save tailorvj/d0a1eb7defede251e31a62a93c38aae0 to your computer and use it in GitHub Desktop.
Save tailorvj/d0a1eb7defede251e31a62a93c38aae0 to your computer and use it in GitHub Desktop.
Dart Map key value pair collection example
main() {
Map map = {
'key1': 'value1',
'key2': 'value2',
'key3': 'value3'
};
print('map.length is ${map.length}');
print('map: $map');
print('map[\'key1\'] is ${map['key1']}');
print('map[\'test\'] is ${map['test']}\n');
//Add a new value
map['key4'] = 'value4';
print('map.length is ${map.length}');
print('map: $map\n');
//Check if a key is present
print('map.containsKey(\'value1\'): ${map.containsKey('value1')}');
print('map.containsKey(\'key3\'): ${map.containsKey('key3')}\n');
//List entries, keys and values
print('map.entries: ${map.entries}');
print('map.keys: ${map.keys}');
print('map.values: ${map.values}');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment