Created
March 25, 2020 12:37
-
-
Save tailorvj/d0a1eb7defede251e31a62a93c38aae0 to your computer and use it in GitHub Desktop.
Dart Map key value pair collection example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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