code: public void ensureCapacity(int capacity) {
          if (capacity > data.length) {
              int newCap = Math.max(data.length << 1, capacity);
              int[] tmp = new int[newCap];
              System.arraycopy(data, 0, tmp, 0, data.length);
              data = tmp;
          }
      }
docs: Increases the capacity, if necessary, to ensure that it can hold
  at least the number of values specified by the minimum capacity
  argument.
  
  @param capacity the desired minimum capacity.