replace method

bool replace(
  1. E element,
  2. E replacement
)

Replaces all element occurrences with replacement.

Returns true if element was replaced. If element is not in the list than will be no changes. If there are multiple element in list - all will be replaced.

Implementation

bool replace(E element, E replacement) {
  var found = false;
  final len = length;
  for (var i = 0; i < len; i++) {
    if (element == this[i]) {
      this[i] = replacement;
      found = true;
    }
  }

  return found;
}