remove方法

bool remove(
  1. Object? element
)
override

从列表中移除第一个出现的value

如果value在列表中,则返回true,否则返回false。列表必须是可增长的。

final parts = <String>['head', 'shoulders', 'knees', 'toes'];
final retVal = parts.remove('head'); // true
print(parts); // [shoulders, knees, toes]

如果value不在列表中,则此方法没有效果。

final parts = <String>['shoulders', 'knees', 'toes'];
// Note: 'head' has already been removed.
final retVal = parts.remove('head'); // false
print(parts); // [shoulders, knees, toes]

实现

bool remove(Object? element) {
  for (int i = 0; i < this.length; i++) {
    if (this[i] == element) {
      this._closeGap(i, i + 1);
      return true;
    }
  }
  return false;
}