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
963287
public Object[] toArray(List<?> list, Class<?> arrayType) {
        int[] dims = findArrayDimensions(list, arrayType);
        Object[] typedArray = (Object[]) Array.newInstance(arrayType, dims);
        return list.toArray(typedArray);
    }
1087122
private String[] mergeAndConvert(List<String> list, String[] array) {
        Set<String> set = new HashSet<String>(Arrays.asList(array));
        set.addAll(list);
        return set.toArray(new String[set.size()]);
    }
417233
public static <T> JSONArray listToJSONArray(final List<T> list) {
        final JSONArray ret = new JSONArray();

        if (null == list) {
            return ret;
        }

        for (final T object : list) {
            ret.put(object);
        }

        return ret;
    }
224677
public static <T> List<T> copy(final List<T> list) {
		if (list == null) {
			return null;
		}

		TypeEnum elementType = null;
		List<T> copy = new ArrayList<T>();
		for (T element : list) {
			T elementCopy = null;
			if (element != null) {
				if (elementType == null) {
					elementType = TypeEnum.dataTypeOf(element.getClass());
				}
				elementCopy = copy(element, elementType);
			}

			copy.add(elementCopy);
		}

		return copy;
	}
1295722
@SuppressWarnings("unchecked")
    public static <T> List<T> jsonArrayToList(final JSONArray jsonArray) {
        if (null == jsonArray) {
            return Collections.emptyList();
        }

        final List<T> ret = new ArrayList<T>();

        for (int i = 0; i < jsonArray.length(); i++) {
            ret.add((T) jsonArray.opt(i));
        }

        return ret;
    }
1287292
public static <T, J extends Convertable<T>> T[] convertToArray(J[] array, Class<T> clazz) {
        return toArray(convert(array), clazz);
    }
849721
public static <T> List<T> cast(List<?> list) {
    return list == null ? null : new CastingList<T>(list);
  }
434471
private static int[] toIntArray(List<Integer> list) {
		int[] array = new int[list.size()];
		int i = 0;
		for (Integer intObj : list) {
			array[i++] = toInt(intObj);
		}
		return array;
	}
1183801
@SuppressWarnings({ "unchecked", "rawtypes" })
	public static List<Object> arrayAsList(Object value) {
		if (value instanceof List) {
			return (List<Object>) value;
		}
		List list = null;
		if (value instanceof int[]) {
			list = new ArrayList();
			int[] array = (int[]) value;
			for (int i : array) {
				list.add(i);
			}
		} else if (value instanceof short[]) {
			list = new ArrayList();
			short[] array = (short[]) value;
			for (short i : array) {
				list.add(i);
			}
		} else if (value instanceof char[]) {
			list = new ArrayList();
			char[] array = (char[]) value;
			for (char i : array) {
				list.add(i);
			}
		} else if (value instanceof byte[]) {
			list = new ArrayList();
			byte[] array = (byte[]) value;
			for (byte i : array) {
				list.add(i);
			}
		} else if (value instanceof long[]) {
			list = new ArrayList();
			long[] array = (long[]) value;
			for (long i : array) {
				list.add(i);
			}
		} else if (value instanceof double[]) {
			list = new ArrayList();
			double[] array = (double[]) value;
			for (double i : array) {
				list.add(i);
			}
		} else if (value instanceof float[]) {
			list = new ArrayList();
			float[] array = (float[]) value;
			for (float i : array) {
				list.add(i);
			}
		} else if (value instanceof boolean[]) {
			list = new ArrayList();
			boolean[] array = (boolean[]) value;
			for (boolean i : array) {
				list.add(i);
			}
		} else if (value.getClass().isArray()) {
			Object[] array = (Object[]) value;
			list = Arrays.asList(array);
		}
		return list;
	}
208621
public ArrayClassInfo getArrayClassInfo(String typeClassName, Type arrayType) {
        ClassInfoImpl elementClassInfo = getDelayableClassInfo(arrayType.getElementType());

        return new ArrayClassInfo(typeClassName, elementClassInfo);
    }
1277611
public static <T> ArrayList<T> newArrayList(Iterator<? extends T> elements) {
        return Lists.newArrayList(elements);
    }
468503
public static Class<?> arrayElementType(Class<?> arrType) {
        if ( null == arrType )
            return null;
        while ( arrType.isArray() )
            arrType = arrType.getComponentType();
        return arrType;
    }
758544
public static <E extends List<Boolean>> E asList(boolean[] array, Class<E> listType) {
		E result;
		try {
			result = listType.newInstance();

			for (Object item : array) {
				result.add((boolean) item);
			}

			return result;
		} catch (InstantiationException | IllegalAccessException e) {
			e.printStackTrace();
			throw (new KriptonRuntimeException(e.getMessage()));
		}
	}
405367
public static <E> List<E> flatten(final List<?> list) {
        List<E> flattened = newArrayList();
        flatten(list, flattened, -1);
        return flattened;
    }
84335
@SuppressWarnings("unchecked")
	public static <T> T[] toArray(Collection<T> col, Class<T> type) {
		return col.toArray((T[]) Array.newInstance(type, 0));
	}
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;
	}
269865
protected <T> List<? extends List<T>> toArrayLists(List<List<T>> lists) {
        for (int i = 0; i < lists.size(); i++) {
            List<T> list = lists.get(i);
            lists.set(i, toArrayList(list));
        }
        return lists;
    }