-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMap.dart
More file actions
51 lines (43 loc) · 1.13 KB
/
Copy pathMap.dart
File metadata and controls
51 lines (43 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
void main() {
var student = {'name': 'Tom', 'age': 21, 'grade': 'A'};
//Creating Maps
//Using Map literal
Map<String, String> capitals = {'Sri Lanka': 'colombo', 'India': 'NewDelhi'};
//Using Map constructor
var fruits = Map();
fruits['apple'] = 'red';
fruits['banana'] = 'yellow';
//accesing variables
print(capitals['India']);
//Add or update entries
capitals['USA'] = 'Wasintion.d.c';
capitals['India'] = 'Delhi';
print(capitals);
//Remove entries
capitals.remove('Sri Lanka');
print(capitals);
//Map Properties & Methods
print(capitals.keys);
print(capitals.values);
print(capitals.length);
print(capitals.isEmpty);
print(capitals.containsKey('India'));
print(capitals.containsValue('Colombo'));
//Loop Through a Map
Map<String, int> scores = {'Math': 90, 'English': 85};
scores.forEach((subject, score) {
print('$subject: $score');
});
//output
// NewDelhi
// {Sri Lanka: colombo, India: Delhi, USA: Wasintion.d.c}
// {India: Delhi, USA: Wasintion.d.c}
// (India, USA)
// (Delhi, Wasintion.d.c)
// 2
// false
// true
// false
// Math: 90
// English: 85
}