Converts Collection to array.
@param <T>
@param col
@param cls
@return
@see java.util.Collection#toArray(T[])
3996
public static <T> T[] toArray(Collection<T> col, Class<T> cls)
    {
        T[] arr = (T[]) Array.newInstance(cls, col.size());
        return col.toArray(arr);
    }
388151
private Object convertArrayToArray(Object array) {
		final Class<?> valueComponentType = ArrayUtil.getComponentType(array);

		if (valueComponentType == targetComponentType) {
			return array;
		}

		final int len = ArrayUtil.length(array);
		final Object result = Array.newInstance(targetComponentType, len);

		final ConverterRegistry converter = ConverterRegistry.getInstance();
		for (int i = 0; i < len; i++) {
			Array.set(result, i, converter.convert(targetComponentType, Array.get(array, i)));
		}
		return result;
	}
706175
@Override
	public Object[] toArray() {
		Object[] result = new Object[size];
		for(int c=0;c<size;c++) result[c] = elementData[c];
		return result;
	}
1347114
public static Object[] toArray(List<?> list) {
	Iterator<?> it = list.iterator();
	Class clazz = null;
	while (it.hasNext()) {
	    Object v = it.next();
	    if (v == null) continue;
	    if (clazz == null) clazz = v.getClass();
	    else if (clazz != v.getClass()) return list.toArray();
	}
	if (clazz == Object.class || clazz == null) return list.toArray();

	Object arr = java.lang.reflect.Array.newInstance(clazz, list.size());
	return list.toArray((Object[]) arr);
    }
204610
public static Class<?>[] toClassArray(Collection<Class<?>> collection) {
		if (collection == null) {
			return null;
		}
		return collection.toArray(new Class<?>[collection.size()]);
	}
424551
@Override
	public <T> T[] toArray(T[] a) {
		combine();
		if(combined==null) {
			Set<E> emptySet = java.util.Collections.emptySet();
			return emptySet.toArray(a);
		}
		return combined.toArray(a);
	}
277237
public static <T> T[] toArray(Class<T> c, List<T> list)
  {
    @SuppressWarnings("unchecked")
    T[] ta= (T[])Array.newInstance(c, list.size());

    for (int i= 0; i<list.size(); i++)
      ta[i]= list.get(i);
    return ta;
  }
983779
@SuppressWarnings("unchecked")
    public static <T> T[] toArray( List<?> list, Class<T> type )
    {
        T[] array = (T[])Array.newInstance( type, list.size() );
        return list.toArray( array );
    }
1264424
@SuppressWarnings("unchecked")
    @Override
    public final <AT> AT[] toArray(AT[] a) {
        this.readLock.lock();
        try {
            // Verify the array size
            if (a.length < this.size) {
                a =
                        (AT[])
                                java.lang.reflect.Array.newInstance(
                                        a.getClass().getComponentType(), this.size);
            }

            // Trick to avoid generics warning
            final Object[] result = a;

            // Copy over all elements
            int index = 0;
            for (final Queue<T> queue : this.keyedQueues.values()) {
                for (final T e : queue) {
                    result[index++] = e;
                }
            }

            // If array is too big set next element null
            if (a.length > this.size) {
                a[this.size] = null;
            }

            return a;
        } finally {
            this.readLock.unlock();
        }
    }
375192
public static Object convertToArray(Object source, Class<?> target) throws ConversionException {
        try {
            Class<?> targetType = target.getComponentType();
            if (source.getClass().isArray()) {
                Object targetInstance = Array.newInstance(targetType, Array.getLength(source));
                for (int i = 0; i < Array.getLength(source); i++) {
                    Array.set(targetInstance, i, convert(Array.get(source, i), targetType));
                }
                return targetInstance;
            }
            if (source instanceof Collection<?>) {
                Collection<?> sourceCollection = (Collection<?>) source;
                Object targetInstance = Array.newInstance(target.getComponentType(), sourceCollection.size());
                Iterator<?> it = sourceCollection.iterator();
                int i = 0;
                while (it.hasNext()) {
                    Array.set(targetInstance, i++, convert(it.next(), targetType));
                }
                return targetInstance;
            }
            throw new ConversionException("Unable to convert to array");
        } catch (Exception ex) {
            throw new ConversionException("Error converting to array", ex);
        }
    }
476677
@NotNull
    public Object[] toArray() {
        return toArray(new IntFunction<Object[]>() {

            @NotNull
            @Override
            public Object[] apply(int value) {
                return new Object[value];
            }
        });
    }
187521
public static <E> E[] asArray(List<E> input, E[] newArray) {
		return input.toArray(newArray);
	}
1321507
public static <T> Object[] toBeanArray(String text, Class<T> clazz) {
        return JSON.parseArray(text, clazz).toArray();
    }
276598
public static Object[] toArray(Object obj)
	{
		if (obj instanceof Object[])
			return (Object[]) obj;
		else
		{
			Object[] returnArray =
			{ obj };
			return returnArray;

		}
	}
1364537
public Collection<?> toCollection(Object val) {

    if (val == null) {
      return Collections.emptyList();
    }
    else if (val instanceof Collection<?>) {
      return (Collection<?>) val;
    }
    else if (val.getClass().isArray()) {
      return newArrayList((Object[]) val);
    }
    else if (val instanceof Map<?,?>) {
      return ((Map<?,?>)val).entrySet();
    }
    else {
      return newArrayList(val);
    }
  }
142096
public static <T> C.List<T> toList(Collection<? extends T> col) {
        if (col.size() == 0) {
            return Nil.list();
        }
        if (col instanceof C.List) {
            C.List<T> list = $.cast(col);
            if (list.is(C.Feature.IMMUTABLE)) {
                return list;
            }
        }
        return new ListBuilder<T>(col).toList();
    }
292257
public static <T> T[] toArray(List<T> list) {
    return toArray(getClass(list.get(0)), list);
  }