Collection in Dart

Collection in Dart

List In Dart

if you want to store multiple values in the same variable, you can use List.

The List is represented by Square Braces[].

Example

void main() 
{
      List<int> nums = [1];
      List<int> nums1 = [1, 2, 3, 4, 5];

      nums[0] = 1;
      nums[1] = 3;
      nums[2] = 4;

      print(nums);
      print(nums1);
}

Fixed Length List

The fixed-length Lists are defined with the specified length.

void main() {  
   var list = List<int>.filled(5,0);  
   print(list);  
}

Growable List

A List defined without a specified length is called Growable List.

void main() {  
   var list1 = [10,1,22,343,480,555];  
   print(list1);  
}