-
Notifications
You must be signed in to change notification settings - Fork 0
/
9_Collections.dart
89 lines (77 loc) · 2.12 KB
/
9_Collections.dart
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
main(List<String> args) {
// List / Array - ordered collection element
List names = ["Vel", "Murugan"];
print(names[0]);
print(names.length);
print("Sample shows list type inferred.");
var namess = ["Vel", "Murugan"];
print(namess[0]);
print(namess.length);
print("Sample shows List with specifc type String.");
List<String> namesss = ["Vel", "Murugan"];
print(namesss[0]);
print(namesss.length);
print("Sample shows constant can't able add/ modify at run time.");
List<String> namessss = const ["Vel", "Murugan"];
//Not allowed in constant.
// namessss[0] = "Raj";
print(namessss[0]);
print(namessss.length);
for (var n in namess) {
print(n);
}
print("Sample shows list is reference type.");
List<String> referenceTypeExample = ["Vel", "Murugan"];
var copyType = referenceTypeExample;
referenceTypeExample.add("Raj");
for (var n in copyType) {
print(n);
}
print("Sample shows list copy.");
List<String> refType = ["Vel", "Murugan"];
var copyRefType = [...refType];
refType.add("Raj");
for (var n in copyRefType) {
print(n);
}
// Set - Unique items of elements.
var helogens = {"fluorine", "chlorines", "chlorines"};
for (var n in helogens) {
print(n);
}
// this will treat as hashmap.
var dynHelogens = {};
print(dynHelogens.runtimeType);
var dynHelogens1 = <String>{};
print(dynHelogens1.runtimeType);
Set<String> n1 = {};
print(n1.runtimeType);
// Map / dictonary
var gifts = {
//Key : value
"first" : "partridge",
"second" : "turtledoves",
"fifth" : "golden rings",
};
print(gifts["fifth"]);
print(gifts.runtimeType);
print(gifts[1]);
print(gifts["emptykey"]);
var giftts = {
//Key : value
"first" : "partridge",
"second" : "turtledoves",
"fifth" : "golden rings",
1 : "golden rings",
};
print(giftts.runtimeType);
// Assign value for keu
var fruits = Map();
print(fruits.runtimeType);
fruits["first"] = "Mango";
print(fruits.runtimeType);
var ft = Map<String , String>();
print(ft.runtimeType);
ft["1"] = "poda"; // good guy
// ft[1] = "poda"; // bad guy
}