# ensureCapacity method

void ensureCapacity(

1. int minCapacity

)

Ensures that the stack can hold at least the specified number of elements.

## Implementation

    void ensureCapacity(int minCapacity) {
      if (_elements.length < minCapacity) {
        final newElements = List<E>.filled(minCapacity, _default as E, growable: true);
        for (int i = 0; i < _elements.length; i++) {
          newElements[i] = _elements[i];
        }
        _elements.clear();
        _elements.addAll(newElements.take(_elements.length));
      }
    }