W3cubDocs

/Dart 2

List<E> constructor

List<E>([int length ])

Creates a list of the given length.

The created list is fixed-length if length is provided.

List fixedLengthList = new List(3);
fixedLengthList.length;     // 3
fixedLengthList.length = 1; // Error

The list has length 0 and is growable if length is omitted.

List growableList = new List();
growableList.length; // 0;
growableList.length = 3;

To create a growable list with a given length, just assign the length right after creation:

List growableList = new List()..length = 500;

The length must not be negative or null, if it is provided.

Implementation

external factory List([int length]);

© 2012 the Dart project authors
Licensed under the Creative Commons Attribution-ShareAlike License v4.0.
https://api.dartlang.org/stable/2.0.0/dart-core/List/List.html