Site icon Automation Dojos

Convert List to Array Using ToArray Without Param

Java provides a toArray method on the ‘List’ interface. This can be used to convert a ‘List’ to an array. Since there are are two overloaded versions, one of these method is explained below.

This toArray method does not accept any input parameters. It returns an object array. The following code snippet demonstrates this approach. Here, the toArray method is invoked on the input List which returns an object array.

Hence this code prints the following output:

2 4 6 8 10
Exit mobile version