To get the length of a list in Dart, you can use the length
property of the List class.
In this example,
numbers
with integer values.length
property of the list object numbers
to get the number of elements in the list.length
property returns the number of elements in the list.void main() {
var numbers = [1, 2, 3, 4, 5];
var length = numbers.length;
print('Length of the list is: \$length');
}
Length of the list is: 5
In this example,
fruits
with string values.length
property of the list object fruits
to get the number of elements in the list.length
property returns the number of elements in the list.void main() {
var fruits = ['apple', 'banana', 'cherry'];
var length = fruits.length;
print('Length of the list is: \$length');
}
Length of the list is: 3
In this tutorial, we learned How to Get Length of a List in Dart language with well detailed examples.