retainAll method

void retainAll(
  1. Iterable<Object?> other
)

Retains all elements that are present in both this list and other.

It's time-complexity is O(n²) if other's contains function is O(n).

[1, 2, 3]..retainAll([1, 2, 4]); // [1, 2]

[1, 2, 3]..retainAll([1, 2, 1]); // [1, 2]

[1, 2, 1]..retainAll([1, 2]); // [1, 2, 1]

Implementation

void retainAll(Iterable<Object?> other) => removeWhere((e) => !other.contains(e));