-
Notifications
You must be signed in to change notification settings - Fork 386
/
31_list_fixed_length.dart
40 lines (28 loc) · 1.06 KB
/
31_list_fixed_length.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
// Objectives
// 1. Fixed-length list
void main() {
// Elements: N N N N N
// Index: 0 1 2 3 4
List<int> numbersList = List(5); // Fixed-length list
numbersList[0] = 73; // Insert operation
numbersList[1] = 64;
numbersList[3] = 21;
numbersList[4] = 12;
numbersList[0] = 99; // Update operation
numbersList[1] = null;// Delete operation
print(numbersList[0]);
print("\n");
// numbersList.remove(73); // Not supported in fixed-length list
// numbersList.add(24); // Not supported in fixed-length list
// numbersList.removeAt(3); // Not supported in fixed-length list
// numbersList.clear(); // Not supported in fixed-length list
for (int element in numbersList) { // Using Individual Element (Objects)
print(element);
}
print("\n");
numbersList.forEach((element) => print(element)); // Using Lambda
print("\n");
for (int i = 0; i < numbersList.length; i++) { // Using Index
print(numbersList[i]);
}
}