What is List remove() in Dart?
The method remove() removes an item from a List by its value.
The List.remove() method removes the first occurrence of the specified item in the list.
Syntax
List_name.remove(Object value);
List_nameis the name of the list.
Parameter
value: This specifies the value of the item that should be removed from the list.
Return value
The remove() method returns true if the specified value is removed from the list.
Code
The following code shows how to use the List remove() method in dart:
void main() {// Creating listList myList = [1,2,3,2,5,6,7,8,9];//Display resultprint('The list before removing the element from the list: ${myList}');bool res = myList.remove(2);print('The new list after removing the element from the list: ${myList}');}
Note: The value
2occurred twice in the list. The methodremove()will remove the first occurrence of the item to be removed from the list.