Working with lists in dart

You,dart + flutter

Dart Arrays Lists

void main() { 
  //example1
  var myList = [1,2,3];
  print(myList);  
  
  //example2
  var someObj = {"hey":"there"}; //some object
  var myList2 = [22/7,"Pi",null,someObj];
  print(myList2);
  
  //print some elements
  print(myList[2]);
  print(myList2[1]);
  
  //modify something
  myList2[2]="plumpkin";
  print(myList2);
  
  //extend the list ?
  myList2.add(1.4142);
  print(myList2);
}

Output:

[1, 2, 3]
[3.142857142857143, Pi, null, {hey: there}]
3
Pi
[3.142857142857143, Pi, plumpkin, {hey: there}]
[3.142857142857143, Pi, plumpkin, {hey: there}, 1.4142]

One way of doing this is to create an array, initially filled with zero (more on this later)

void main() { 
   var lst = new List.filled(3,0); //create array of size 3 filled with zeros
   lst[0] = 12; 
   lst[1] = 13; 
   lst[2] = 11; 
   print(lst); 
   print(lst[2]);
 
 
}

which gives the output:

[12, 13, 11]
11