Dart – List Length

To get the length of a List in Dart, read its length property. length property is read-only for fixed length lists and writable for growable lists.

Syntax

The syntax to read length property of a List list is

list.length
ADVERTISEMENT

Example

In this example, we take a list of integers and find the length of this list programmatically using List.length property.

main.dart

void main() {
  var list = [2, 4, 8, 16, 32];
  var len = list.length;
  print('Length of given list : $len');
}

Output

Length of given list : 5

Conclusion

In this Dart Tutorial, we learned how to get the length of a list, with examples.