public static Object toArray(Collection<?> collection,Class<?> componentType){
  if (componentType.isPrimitive()) {
    Object array=Array.newInstance(componentType,collection.size());
    int index=0;
    for (    Object value : collection) {
      Array.set(array,index++,value);
    }
    return array;
  }
  return collection.toArray((Object[])Array.newInstance(componentType,collection.size()));
}

public static Object toArray ( Collection < ? > collection , Class < ? > componentType ) { if ( componentType . isPrimitive ( ) ) { Object array = Array . newInstance ( componentType , collection . size ( ) ) ; int index = 0 ; for ( Object value : collection ) { Array . set ( array , index ++ , value ) ; } return array ; } return collection . toArray ( ( Object [ ] ) Array . newInstance ( componentType , collection . size ( ) ) ) ; }
returns a new array of the given component type ( possibly a java primitive ) that is a copy of the content of the given collection .
