The List.removeLast()
method in Dart removes the last item from the list and returns it.
List_name.removeLast();
List_name
is the name of the list.
The removeLast()
method takes no parameter.
The removeLast()
method returns the last item removed from the list.
The following code shows how to use the removeLast()
method in Dart:
void main() {// Create the listList myList = ['Mango', 'Apple', 'Pineapple', 'Lemon'];// Display the resultsprint('The list before removing the last item: ${myList}');// Assign the items removed to variable resvar res = myList.removeLast();// Display the valueprint('The value of item removed: ${res}');// Display the resultsprint('The new list after removing the last item: ${myList}');}
res
.