Flash cards
Review the key moves
What is the main idea behind Java ArrayList toArray() Method?
Lesson checks
Practice each idea before moving on
Short Mimo-style checks built from this lesson's code, terms, and sequence.
Which statement best captures the main point of this lesson?
Put the learning moves in the order that makes the concept easiest to apply.
❮ ArrayList Methods
ArrayListDefinition and Usage
The toArray() method returns an array containing all of the items in the list.
If no argument is passed then the type of the returned array will be Object . If an array is passed as an argument then this method will return an array with the same data type.
If the array in the argument is large enough to contain all of the list items then this method will return the argument itself after writing the list items into it.
One of the following
public Object[] toArray()public T[] toArray(T[]
array )T refers to the data type of items in the list.
Parameter Values
| Parameter | Description |
|---|---|
| array | Optional. An array which specifies the data type of the returned array and will be returned by the method if it has enough space for the items in the list. If the array is not large enough then the method returns a new array of the same data type. |
Technical Details
| Returns: | An array containing all of the elements of the ArrayList in order. |
|---|---|
| Throws: | ArrayStoreException - If the type of the array is not compatible with the type of the ArrayList . NullPointerException - If the argument is null . |