Collection Interface Array Operations
The toArray methods are provided as a bridge between collections and older APIs that expect arrays on input. The array operations allow the contents of a Collection to be translated into an array. The simple form with no arguments creates a new array of Object. The more complex form allows the caller to provide an array or to choose the runtime type of the output array.
For example, suppose that c is a Collection. The following snippet dumps the contents of c into a newly allocated array of Object whose length is identical to the number of elements in c.
Object[] a = c.toArray();
Suppose that c is known to contain only strings (perhaps because c is of type Collection). The following snippet dumps the contents of c into a newly allocated array of String whose length is identical to the number of elements in c.
Object[] a = c.toArray();
References : Oracle
share on : :
Love to hear your Views / Guidance / Recommendations on this Post…