The syntax of List.last property is:
This last property of List the last element.
List.last returns value of type .
In this example,
numbers
containing the integers [1, 2, 3]
.last
property to retrieve the last element of the list.lastNumber
.void main() {
List<int> numbers = [1, 2, 3];
int lastNumber = numbers.last;
print('Last number: $lastNumber'); // Output: Last number: 3
}
Last number: 3
In this example,
characters
containing the characters ['a', 'b', 'c']
.last
property to retrieve the last element of the list.lastCharacter
.void main() {
List<String> characters = ['a', 'b', 'c'];
String lastCharacter = characters.last;
print('Last character: $lastCharacter'); // Output: Last character: c
}
Last character: c
In this example,
strings
containing the strings ['apple', 'banana', 'cherry']
.last
property to retrieve the last element of the list.lastString
.void main() {
List<String> strings = ['apple', 'banana', 'cherry'];
String lastString = strings.last;
print('Last string: $lastString'); // Output: Last string: cherry
}
Last string: cherry
In this Dart tutorial, we learned about last property of List: the syntax and few working examples with output and detailed explanation for each example.