Dart by Example: Map
1. main() {
3. // adding keys
4. var colors = new Map();
5. colors['blue'] = false;
6. colors['red'] = true;
7. print(colors);
9. // curly bracket literals can also be used:
10. var shapes = {
11. 'square': false,
12. 'triangle': true
13. };
14. print(shapes);
16. // keys and values can be iterated.
17. // HashMap iterates in arbitrary order, while LinkedHashMap, and SplayTreeMap
18. // iterate in the order they were inserted into the map.
19. for (var key in shapes.keys) print(key);
20. for (var value in shapes.values) print(value);
21. }
1. $ dart map.dart
2. {blue: false, red: true}
3. {square: false, triangle: true}
4. square
5. triangle
6. false
7. true
by @jryanio | source | license