List can also be converted to an array using stream concept (Stream concept has been introduced in java 1.8 version).

Steps to convert a list (using toArray(IntFunction<A[]> generator) method) into an array Using Stream

(1.) Use stream() method on list .
stream() method returns a stream with the collection as its source.
List<String> list = new ArrayList<String>();
list.add(“Kiran”);
list.add(“Devgan”);
Stream<String> s = list.stream();

(2.) Use toArray(IntFunction<A[]> generator) method on the the stream obtained

String []strArray = s.toArray(String[] :: new);

Here, argument in the method should be of same type as the objects contained in the Stream . toArray(IntFunction<A[]> generator) method would return the array of same types as that of object type contained in the Stream.

Demo Program to Convert list into an array Using Stream in Java 8

The below demo program explains how to to Convert list into an array Using Stream in Java 8.

Example.java

package com.masterjavatutorial;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;

public class Example {

	public static void main(String[] args) {
	      
		List<String> list = new ArrayList<String>();
		list.add("Agra");
		list.add("Mumbai");
		list.add("Bangalore");
		list.add("Kolkatta");
		list.add("Patna");
		list.add("Lucknow");
		
		Stream<String> s = list.stream();   
		String []strArray = s.toArray(String[] :: new);
		for(String str : strArray){
		   System.out.println(str); 
		}
		
	}

}

Output of the above Program is as below:

Agra
Mumbai
Bangalore
Kolkatta
Patna
Lucknow