code: public static <T> T[] toArray(Class<T> classToCastTo, Collection c)
      {
          T[] array = (T[]) c.toArray((T[]) Array.newInstance(classToCastTo, c.size()));
          Iterator i = c.iterator();
          int idx = 0;
          while (i.hasNext())
          {
              Array.set(array, idx++, i.next());
          }
          return array;
      }
docs: Convert Collection to a Java (typed) array [].
  @param classToCastTo array type (Object[], Person[], etc.)
  @param c Collection containing items to be placed into the array.
  @param <T> Type of the array
  @return Array of the type (T) containing the items from collection 'c'.