The syntax of List.length property is:
This length property of List the number of objects in this list.
List.length returns value of type .
In this example,
numbers
containing integers.length
property to get the length of the list.void main() {
List<int> numbers = [1, 2, 3, 4, 5];
int listLength = numbers.length;
print('Length of numbers list: $listLength');
}
Length of numbers list: 5
In this example,
characters
containing strings.length
property to get the length of the set.void main() {
Set<String> characters = {'a', 'b', 'c'};
int setLength = characters.length;
print('Length of characters set: $setLength');
}
Length of characters set: 3
In this example,
str
with a value.length
property to get the length of the string.void main() {
String str = 'Hello, world!';
int strLength = str.length;
print('Length of string: $strLength');
}
Length of string: 13
In this Dart tutorial, we learned about length property of List: the syntax and few working examples with output and detailed explanation for each example.