-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path#38-Growable_List.dart
58 lines (45 loc) · 1.51 KB
/
#38-Growable_List.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
void main(){
//List in Dart
//Array is also known as List in Dart.
//list is collection of data in a systemetic manner.
/*
Types of Array/List in Dart
1.Fixed Length list
2.Growable List
*/
//By Default all the value is null
//Syntax -->
//Growable Length List
//Method 1
List<String> coutries = ["India", "Usa", "Kanada"]; //add item this will added to the list.
//Method 2
List<int> numberList = List(); // Don't add any parameter to make it a growable list.
//add value to the list -->
numberList.add(32);//The parameter will be the value and its added to the index 0
numberList.add(56);//The parameter will be the value and its added to the index 1
numberList.add(20);//The parameter will be the value and its added to the index 2
//update the value-->
numberList[0]= 55;
//Remove the Value-->
numberList.remove(20); // the parameter will be the value you want to remove
numberList.removeAt(1); //the parameter will be the index position which index value you want to remove.
//Displaying the Value
//1st Method -->
print(coutries[1]);
print("\n");
//2nd Method -->
//using for in loop
for(int list in numberList){
print(list);
}
print("\n");
//3rd Method -->
//using for each loop
numberList.forEach((list) => print(list));
print("\n");
//4th Method -->
//using forloop
for(int i= 0;i < numberList.length; i++){
print(numberList[i]);
}
}