CollectionUtils { public static <T> Object convertListToArray(List<T> list, Class<T> destEntryType) { Object outArray = Array.newInstance(destEntryType, list.size()); int count = 0; int size = list.size(); for (int i = 0; i < size; i++) { Object element = list.get(i); Array.set(outArray, count, element); count++; } if (destEntryType.isPrimitive()) { return outArray; } else { return outArray; } } private  CollectionUtils(); static boolean isArray(Class<?> aClass); static boolean isCollection(Class<?> aClass); static boolean isList(Class<?> aClass); static boolean isSet(Class<?> aClass); static boolean isPrimitiveArray(Class<?> aClass); static int getLengthOfCollection(Object value); static Object getValueFromCollection(Object collection, int index); static Set<?> createNewSet(Class<T> destType); static Set<?> createNewSet(Class<T> destSetType, Collection<?> srcValue); static Object convertListToArray(List<T> list, Class<T> destEntryType); static List<Object> convertPrimitiveArrayToList(Object primitiveArray); static Set<E> intersection(final Set<E> set1, final Set<?> set2);  }
@Test public void testConvertListToArray() { List<String> src = Arrays.asList("a", "b"); String[] result = (String[])CollectionUtils.convertListToArray(src, String.class); assertTrue("wrong result value", Arrays.equals(new String[] {"a", "b"}, result)); }