code: public static Object convertToArray(final Class type, final List<?> values) {
          final Object exampleArray = Array.newInstance(type, values.size());
          try {
              return values.toArray((Object[]) exampleArray);
          } catch (ClassCastException e) {
              for (int i = 0; i < values.size(); i++) {
                  Array.set(exampleArray, i, values.get(i));
              }
              return exampleArray;
          }
      }
docs: Converts a List to an array
  
  @param type   the Class type of the elements of the List
  @param values the List to convert
  @return the array