java.util.List.toArray(T[] t) method can be used to convert a list to an array.

Syntax of List toArray(T[] t) Method

 T[] toArray(T[] a);

This method returns an array object containing elements in the same sequence as the list insertion order. The runtime type of the returned array is that of the specified array. Return type is the same which is passed as an argument to toArray(T[] t) method.
e.g.

List list = new ArrayList();
list.add(new Employee(“DK”,28));
list.add(new Employee(“Arjun”,32));
list.add(new Employee(“Krish”,33));
Employee emp[] = list.toArray(new Employee[0]);

Example.java

The below program demonstrates how to use toArray(T[] t) method on a list object.

package com.masterjavatutorial;
import java.util.ArrayList;
import java.util.List;

public class Example {

	public static void main(String[] args) {
      
		List list = new ArrayList();
		list.add("Delhi");
		list.add("Mumbai");
		list.add("Bangalore");
		list.add("Kolkatta");
		list.add("Patna");
		list.add("Lucknow");
		
		String[] array = list.toArray(new String[0]); 
		for(String obj : array){
		   System.out.println(obj);
		}
		
	}

}

Output of the above program is as below:

Delhi
Mumbai
Bangalore
Kolkatta
Patna
Lucknow

toArray(T[] t) method returns array object which is the same as which is passes as an argument containing elements in the same order as that of the list.