removeAt method
Removes the object at position index
from this list.
This method reduces the length of this
by one and moves all later objects
down by one position.
Returns the removed value.
The index
must be in the range 0 ≤ index < length
.
The list must be growable.
final parts = <String>['head', 'shoulder', 'knees', 'toes'];
final retVal = parts.removeAt(2); // knees
print(parts); // [head, shoulder, toes]
Implementation
@override
E removeAt(int index) {
_checkIndex(index);
if (index == 0) {
return pop();
}
// Convert to list, remove, and rebuild stack
final list = toList();
final removed = list.removeAt(_size - 1 - index);
clear();
for (final item in list.reversed) {
push(item);
}
return removed;
}