code: public static Object[] resizeIfNeeded(Object[] arr, int minSize, boolean doPowerOf2) {
  
  	if (arr.length >= minSize) return arr;
  
  	if (doPowerOf2) minSize = MathUtil.nextPowerOf2(minSize);
  
  	Object[] result = new Object[minSize];
  	System.arraycopy(arr, 0, result, 0, arr.length);
  
  	return result;
      }
docs: this method returns the original array if its length is equal or greater than the minSize, or
  create a new array and copies the data from the original array into the new one.
  
  @param arr - the array to check
  @param minSize - the required minimum size
  @param doPowerOf2 - if true, and a resize is required, the new size will be a power of 2
  @return - either the original arr array if it had enough capacity, or a new array.