code: public Object[] toArray(List<?> list, Class<?> arrayType) {
          int[] dims = findArrayDimensions(list, arrayType);
          Object[] typedArray = (Object[]) Array.newInstance(arrayType, dims);
          return list.toArray(typedArray);
      }
docs: Convert the given list to an array of the given array type.
  
  @param list The list to convert
  @param arrayType The type of array to create
  
  @return The array of elements in the list