Either:

Foo[] array = list.toArray(new Foo[0]);

or:

Foo[] array = new Foo[list.size()];
list.toArray(array); // fill the array

Note that this works only for arrays of reference types. For arrays of primitive types, use the traditional way:

List<Integer> list = ...;
int[] array = new int[list.size()];
for(int i = 0; i < list.size(); i++) array[i] = list.get(i);

Update:

It is recommended now to use list.toArray(new Foo[0]);, not list.toArray(new Foo[list.size()]);.

From JetBrains Intellij Idea inspection:

There are two styles to convert a collection to an array: either using a pre-sized array (like c.toArray(new String[c.size()])) or using an empty array (like c.toArray(new String[0]).

In older Java versions using pre-sized array was recommended, as the reflection call which is necessary to create an array of proper size was quite slow. However since late updates of OpenJDK 6 this call was intrinsified, making the performance of the empty array version the same and sometimes even better, compared to the pre-sized version. Also passing pre-sized array is dangerous for a concurrent or synchronized collection as a data race is possible between the size and toArray call which may result in extra nulls at the end of the array, if the collection was concurrently shrunk during the operation.

This inspection allows to follow the uniform style: either using an empty array (which is recommended in modern Java) or using a pre-sized array (which might be faster in older Java versions or non-HotSpot based JVMs).

Answer from Eng.Fouad on Stack Overflow
Top answer
1 of 11
1518

Either:

Foo[] array = list.toArray(new Foo[0]);

or:

Foo[] array = new Foo[list.size()];
list.toArray(array); // fill the array

Note that this works only for arrays of reference types. For arrays of primitive types, use the traditional way:

List<Integer> list = ...;
int[] array = new int[list.size()];
for(int i = 0; i < list.size(); i++) array[i] = list.get(i);

Update:

It is recommended now to use list.toArray(new Foo[0]);, not list.toArray(new Foo[list.size()]);.

From JetBrains Intellij Idea inspection:

There are two styles to convert a collection to an array: either using a pre-sized array (like c.toArray(new String[c.size()])) or using an empty array (like c.toArray(new String[0]).

In older Java versions using pre-sized array was recommended, as the reflection call which is necessary to create an array of proper size was quite slow. However since late updates of OpenJDK 6 this call was intrinsified, making the performance of the empty array version the same and sometimes even better, compared to the pre-sized version. Also passing pre-sized array is dangerous for a concurrent or synchronized collection as a data race is possible between the size and toArray call which may result in extra nulls at the end of the array, if the collection was concurrently shrunk during the operation.

This inspection allows to follow the uniform style: either using an empty array (which is recommended in modern Java) or using a pre-sized array (which might be faster in older Java versions or non-HotSpot based JVMs).

2 of 11
409

An alternative in Java 8:

String[] strings = list.stream().toArray(String[]::new);

Since Java 11:

String[] strings = list.toArray(String[]::new);
🌐
GeeksforGeeks
geeksforgeeks.org › java › convert-list-to-array-in-java
Convert List to Array in Java - GeeksforGeeks
July 11, 2025 - This Java program demonstrates how to convert a LinkedList of strings to an array using the get() method in a loop. It creates a LinkedList, adds elements to it, then iterates through the list to copy each element into an array.
Discussions

Converting array to list in Java - Stack Overflow
Indeed, I tried some code and confirmed that calling List::add & List::remove fails with a list returned by Arrays.asList. The JavaDoc for that method is poorly written and unclear on this point. On my third reading, I suppose the phrase “fixed-size” there was meant to say one cannot add ... More on stackoverflow.com
🌐 stackoverflow.com
Convert List into an array in Java
As u/durakkiller pointed out, the convenient way to do that is the way you provide yourself. Now let's discuss why Java doesn't come with a handy way to do that conversion. Most likely, because there is no demand. No one ever wants to make such conversions, and you shouldn't either. List to Employe[] -> Dont. Keep the list. Why would you want an array? List to int[] -> If you need an array of ints, start with an array of ints. Don't start with a List. If you don't need an array of ints, start with and keep a List. More on reddit.com
🌐 r/learnjava
8
1
July 17, 2020
Converting Arrays to Arraylist
In this case, Arrays.asList() produces a list of arrays, i.e., List. A normal iterative approach is best to populate the list. It may also be possible to do this with Streams, if you can use those. More on reddit.com
🌐 r/javahelp
7
10
April 26, 2022
Java: Is Arraylist better than Arrays?
The biggest difference is that you can add to and remove from a list, whereas arrays have a fixed size. More on reddit.com
🌐 r/learnprogramming
28
19
June 23, 2024
People also ask

Are there common errors to watch out for when converting a List to an Array in Java? How can they be avoided?
Common errors include type mismatches and NullPointerExceptions. Ensure your List and Array types match, initialize your Array properly to avoid these issues, and always check for null values before converting a List to an Array.
🌐
upgrad.com
upgrad.com › home › tutorials › software & tech › converting a list to an array in java
Converting a List to an Array in Java - A Comprehensive Guide
What are the potential drawbacks of converting a List to an Array in terms of memory usage and performance?
The potential drawbacks of converting a List to an Array in terms of memory usage and performance include possible memory overhead, resizing limitations, and immutability. Careful consideration of size requirements and understanding the specific needs of the program can help mitigate these drawbacks.
🌐
upgrad.com
upgrad.com › home › tutorials › software & tech › converting a list to an array in java
Converting a List to an Array in Java - A Comprehensive Guide
In what scenarios would it be preferable to use a List, and when would it be better to use an Array?
Lists are ideal for dynamically-sized data and when elements' insertion and removal are frequent, while Arrays are better for fixed-size data, operations involving indices, and when you need efficiency in memory and speed.
🌐
upgrad.com
upgrad.com › home › tutorials › software & tech › converting a list to an array in java
Converting a List to an Array in Java - A Comprehensive Guide
🌐
CodeGym
codegym.cc › java blog › java collections › convert list to array in java
Convert List to Array in Java
December 10, 2024 - Add elements to the List through the list.add(data_type) method. Create an Array with the same size as the list. Convert the List into an Array by using the variable name of the array created in step 3 as an argument.
🌐
Upgrad
upgrad.com › home › tutorials › software & tech › converting a list to an array in java
Converting a List to an Array in Java - A Comprehensive Guide
1 month ago - The toArray() method returns an array containing all the elements of the List in the same order. In this case, the List contains three elements, so the resulting array, fruitsArray, will also have a size of three.
🌐
DZone
dzone.com › data engineering › data › how to convert between list and array in java
How to Convert Between List and Array in Java - DZone
August 1, 2018 - The Guava wrapper classes come with a toArray() method that returns a primitive array containing each value of the collection passed to it. The code to convert a list to a primitive array using Guava would look like this:
Find elsewhere
🌐
Programiz
programiz.com › java-programming › examples › convert-list-array
Java Program to Convert a List to Array and Vice Versa
Here, the toArray() method converts the list languages into an array. And stores it in the string array arr. Note: If we don't pass any argument to the toArray() method, the method returns an array of the Object type. import java.util.Arrays; import java.util.ArrayList; import java.util.List; ...
🌐
W3Schools
w3schools.com › java › java_arraylist.asp
Java ArrayList
It is part of the java.util package and implements the List interface. The difference between a built-in array and an ArrayList in Java, is that the size of an array cannot be modified (if you want to add or remove elements to/from an array, you have to create a new one).
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › util › ArrayList.html
ArrayList (Java Platform SE 8 )
July 21, 2026 - Java™ Platform Standard Ed. 8 ... public class ArrayList<E> extends AbstractList<E> implements List<E>, RandomAccess, Cloneable, Serializable · Resizable-array implementation of the List interface. Implements all optional list operations, and permits all elements, including null. In addition to ...
🌐
Educative
educative.io › answers › how-to-convert-a-java-list-to-an-array
How to convert a Java list to an array
This conversion is done using the toArray() method of the List interface. ... This method returns an array of type Object[] whose elements are all in the same sequence as they are in the list.
🌐
Scaler
scaler.com › home › topics › convert list to array in java
Convert List to Array in Java - Scaler Topics
April 14, 2023 - The toArray() method is a popular method used to convert list to array in java.
🌐
How to do in Java
howtodoinjava.com › home › java array › convert a list to array and back in java
Convert a List to Array and back in Java
February 3, 2023 - Similarly, we learned to get the list from an array using the Arrays.asList() method. There are a few other ways, for example, using Apache Commons and Guava APIs, but it is overkill to do this simple job without any clear benefit.
🌐
Index.dev
index.dev › blog › convert-list-to-array-java
Convert List to Array in Java: 6 Best Ways
May 28, 2025 - Convert list to array Java with top methods: toArray(), Stream API, manual loops, and reflection. Gain performance insights and type safety tips.
🌐
Reddit
reddit.com › r/learnjava › convert list into an array in java
r/learnjava on Reddit: Convert List into an array in Java
July 17, 2020 -

Suppose we have a List<Employee> object and we want to convert it into Employee[ ].

List<Employee> list=new ArrayList<>();

We can convert list to object type array in following ways:

Employee[] empArray = list.toArray(new Employee[0]);

or

Employee[] empArray = new Employee[list.size()];

list.toArray(empArray);

But to convert arrays to primitive types. you have to convert it into following way:-

List<Integer> list = ...;

int[] array = new int[list.size()];

for(int i = 0; i < list.size(); i++) array[i] = list.get(i);

Is there any other way to convert List to its specific type of array?

🌐
Java2Blog
java2blog.com › home › conversion › java convert list to array
Java convert List to Array - Java2Blog
January 11, 2021 - There two overloaded methods for toArray(). Syntax: Where,T represents generic. ... Please note that if you do not pass any parameter to toArray() method, it will give us Object array. We can simply use java 8‘ stream’s toArray() method to convert List to array.
🌐
TutorialsPoint
tutorialspoint.com › article › how-to-convert-between-list-and-array-in-java
How to convert between List and Array in Java?
May 27, 2025 - Using iteration, we can not directly convert a list to an Array, but we can iterate through the list elements, and using the assignment '=' operator and the get() method, we assign all the list elements to the array one by one.
🌐
Initial Commit
initialcommit.com › blog › java-convert-list-to-array
Java – Convert List to Array - Initial Commit
The other way of converting a List ... namesArr; } With Java 8, you can convert a List to Array in one line using stream() and toArray() utility methods....
🌐
GeeksforGeeks
geeksforgeeks.org › java › arraylist-array-conversion-java-toarray-methods
ArrayList to Array Conversion in Java : toArray() Methods - GeeksforGeeks
July 11, 2026 - Supports multiple conversion techniques, including toArray(), manual copying with get(), and the Java Stream API. We can use any of the following methods to convert an ArrayList to an array, depending on the type of array and your specific requirements. It is specified by toArray in interface Collection and interface List
🌐
W3Schools
w3schools.com › java › ref_arraylist_toarray.asp
Java ArrayList toArray() Method
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. ... T refers to the data type of items in the list. ... import java.util.ArrayList; public class Main { public static void main(String[] args) { ArrayList<String> cars = new ArrayList<String>(); cars.add("Volvo"); cars.add("BMW"); cars.add("Ford"); cars.add("Mazda"); String[] carsArray = new String[4]; carsArray = cars.toArray(carsArray); for(String item : carsArray) { System.out.println(item); } } }
🌐
Vultr Docs
docs.vultr.com › java › examples › convert a list to array and vice versa
Java Program to Convert a List to Array and Vice Versa
November 25, 2024 - In this article, you will learn how to convert a list to an array and an array to a list using straightforward examples. Explore the implementation through concise and practical code examples to solidify your understanding of managing collections in Java.