code: public void ensureCapacity(int size) {
      if (size > elements.length) {
        reallocate(Math.max(size, 2 * elements.length));
      }
    }
docs: Ensures that there is enough room in the array to hold the specified
  number of elements.
  
  @param size
  The required capacity.