remove method
Removes the first occurrence of value
from this list.
Returns true if value
was in the list, false otherwise.
The list must be growable.
final parts = <String>['head', 'shoulders', 'knees', 'toes'];
final retVal = parts.remove('head'); // true
print(parts); // [shoulders, knees, toes]
The method has no effect if value
was not in the list.
final parts = <String>['shoulders', 'knees', 'toes'];
// Note: 'head' has already been removed.
final retVal = parts.remove('head'); // false
print(parts); // [shoulders, knees, toes]
Implementation
@override
bool remove(Object? value) {
_Node<E>? current = _head;
while (current != null) {
if (current.value == value) {
if (current.prev != null) {
current.prev!.next = current.next;
} else {
_head = current.next; // Removing head
}
if (current.next != null) {
current.next!.prev = current.prev;
} else {
_tail = current.prev; // Removing tail
}
_length--;
return true;
}
current = current.next;
}
return false;
}