If the collection fits in the specified array with room to spare (i.e., * the array has more elements than the collection), the element in the array * immediately following the end of the collection is set to null. This is * useful in determining the length of the collection only if the * caller knows that the collection does not contain any null elements. * *
This method returns the elements in the order they are returned by the * collection's iterator. * *
TODO: Support concurrent collections whose size can change while the
* method is running.
*
* @param c the collection for which to return an array of elements
* @param array the array in which to place the collection elements
* @throws ArrayStoreException if the runtime type of the specified array is
* not a supertype of the runtime type of every element in the specified
* collection
*/
static This method assumes that the collection size doesn't change while the
* method is running.
*
* TODO: Support concurrent collections whose size can change while the
* method is running.
*
* @param c the collection for which to return an array of elements
*/
static Object[] toArrayImpl(Collection> c) {
return fillArray(c, new Object[c.size()]);
}
private static Object[] fillArray(Iterable> elements, Object[] array) {
int i = 0;
for (Object element : elements) {
array[i++] = element;
}
return array;
}
}