Site icon Automation Dojos

Convert List to Array Using For-Loop

The simplest way to convert a List to an array is to use a for-loop. The following code snippet demonstrates this method.

First, the code creates an Array based on the number of elements in the input List. A for-loop is then used which iterates through the input List and adds each element of the List to an Array. Finally, another for-loop is used to print each element in the array.

So this code prints the following output:

2 4 6 8 10
Exit mobile version