# remove method

1. @override

V? remove(

1. Object? key

)
override

Removes `key` and its associated value, if present, from the map.

Returns the value associated with `key` before it was removed. Returns `null` if `key` was not in the map.

Note that some maps allow `null` as a value, so a returned `null` value doesn't always mean that the key was absent.

    final terrestrial = <int, String>{1: 'Mercury', 2: 'Venus', 3: 'Earth'};
    final removedValue = terrestrial.remove(2); // Venus
    print(terrestrial); // {1: Mercury, 3: Earth}

## Implementation

    @override
    V? remove(Object? key) {
      if (isEmpty) return null;

      final index = _getBucketIndex(key);
      final bucket = _buckets[index];

      if (bucket != null) {
        for (int i = 0; i < bucket.length; i++) {
          if (bucket[i].key == key) {
            final removedValue = bucket[i].value;
            bucket.removeAt(i);
            _size--;
            // If bucket becomes empty, set to null to save memory (optional)
            if (bucket.isEmpty) {
              _buckets[index] = null;
            }
            return removedValue;
          }
        }
      }
      return null;
    }