code: private void reallocate(int capacity) {
      if (capacity != elements.length) {
        assert (size <= capacity);
        float[] newArray = new float[capacity];
        for (int i = 0; i < size; i++) {
          newArray[i] = elements[i];
        }
        elements = newArray;
      }
    }
docs: Resizes the underlying array.
  
  @param capacity
  The new size for the underlying array.