code: @SuppressWarnings("unchecked")
      public static <T> T[] toArray(Collection<T> collection, Class<T> clazz) {
          if (collection == null) {
              return null;
          }
          return collection.toArray((T[]) Array.newInstance(clazz, collection.size()));
      }
docs: Converting {@link java.util.List List} into array of given type.