code: public static short[] ensureCapacity(short[] elements, int size) {
          if (size > elements.length) {
              short[] tmp = new short[size*2];
              System.arraycopy(elements, 0, tmp, 0, elements.length);
              elements = tmp;
          }
          return elements;
      }
docs: Ensure that the array has space to contain the specified number of elements.
  @param elements The array.
  @param size The number of elements.