removeWhere 方法

void removeWhere(
  1. bool test(
    1. E element
    )
)
override

移除满足 test 的该集合中所有元素。

final characters = <String>{'A', 'B', 'C'};
characters.removeWhere((element) => element.startsWith('B'));
print(characters); // {A, C}

实现

void removeWhere(bool test(E element)) {
  List<Object?> toRemove = [];
  for (E element in this) {
    if (test(element)) toRemove.add(element);
  }
  removeAll(toRemove);
}