-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathList.dart
More file actions
58 lines (50 loc) · 1.02 KB
/
List.dart
File metadata and controls
58 lines (50 loc) · 1.02 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
52
53
54
55
56
57
58
void main() {
//create a list
var List1 = [1, 2, 3];
List<String> names = ['Tom', 'Jerry'];
//Access List elements
List<String> cities = ['Colombo', 'Kandy'];
print(cities[0]);
print(cities.length);
//Modify the list
List<int> numbers = [1, 2, 3];
numbers[0] = 10;
print(numbers);
//Add items
List<String> name = ['A', 'B'];
name.add('c');
name.addAll(['D', 'E']);
print(name);
//remove items
List<String> letters = ['A', 'B', 'C'];
letters.remove('B');
letters.removeAt(0);
print(letters);
//Check If List Contains Item
List<String> colors = ['red', 'blue'];
print(colors.contains('blue'));
//Loop Through a List
List<int> nums = [10, 20, 30];
for (var n in nums) {
print(n);
}
nums.forEach((n) => print(n));
//spread and rest
List<int> base = [1, 2];
List<int> combined = [...base, 3, 4];
print(combined);
//outputs
// Colombo
// 2
// [10, 2, 3]
// [A, B, c, D, E]
// [C]
// true
// 10
// 20
// 30
// 10
// 20
// 30
// [1, 2, 3, 4]
}