bugl
bugl
HomeLearnPatternsPathsSearch
HomeLearnPatternsPathsSearch

Loading lesson path

Learn/Java/Java Reference
Java•Java Reference

Java ArrayList toArray() Method

Flash cards

Review the key moves

1/4
Core idea

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.

1Quick choice

Which statement best captures the main point of this lesson?

2Order

Put the learning moves in the order that makes the concept easiest to apply.

The toArray() method returns an array containing all of the items in the list.
Definition and Usage
Java ArrayList toArray() Method

❮ ArrayList Methods

ArrayList

Definition 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

ParameterDescription
arrayOptional. 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 .

Previous

Java ArrayList subList() Method

Next

Java ArrayList trimToSize() Method