Middle
How can you copy elements from any collection into an array in one line?
sobes.tech AI
Answer from AI
// Copy all elements of the collection into an array, the array type is determined automatically based on the type of collection elements
collection.toArray();
// Copy the elements of the collection into an array of a specified type. If the size of the input array is smaller than the number of elements in the collection, a new array of the appropriate size will be created.
collection.toArray(new Type[0]);
// Copy the elements of the collection into an existing array. If the size of the input array is sufficient, the elements will be copied into it. If not, a new array will be created.
collection.toArray(existingArray);