xxxxxxxxxx
-----Fixed Length List----
var list_name = [initial_size];
lst_name[index] = value;
----Growable List------
var list_name = [val1,val2,val3];
OR
var list_name = [];
list_name[index] = value;
xxxxxxxxxx
main(List<String> args) {
//Syntax : List<ValuesDataType> ListName = [Values]
List<int> x = [10, 20, 30, 50, 70, 90];
//? printing specific value : print (ListNameHere[ItsArrangeStartFrom0]);
//! example
print(x[0]);
//? printing the whole list : print (ListName)
print(x);
//? calculate list values :
//! example
print(x[0] * x[5]);
//? to add a new value to the list use <ListName>.add(Value);
//! example
x.add(155);
}
xxxxxxxxxx
var fixedLengthList = List<int>.filled(5, 0);
fixedLengthList.length = 0; // Error
fixedLengthList.add(499); // Error
fixedLengthList[0] = 87;
var growableList = [1, 2];
growableList.length = 0;
growableList.add(499);
growableList[0] = 87;
xxxxxxxxxx
List<String> foo = new List.from(<int>[1, 2, 3]); // okay until runtime.
List<String> bar = new List.of(<int>[1, 2, 3]); // analysis error
xxxxxxxxxx
void main() {
List<List<String>> oneArray = []; // This is the 'parent' list of lists
List<String> oneRow1 = ['A', 'B', 'C']; // Child list 1
List<String> oneRow2 = ['D', 'E', 'F']; // Child list 2
oneArray.add(oneRow1); // Add child lists to parent
oneArray.add(oneRow2);
print('List of lists example');
print('array 1 = $oneArray. cell (1,1) = ${oneArray[1][1]}'); // Access element in list of lists
}