Java is a programming language that implements data structures like Arrays, Lists, HashMaps, Trees, etc. Each of these exists with its advantages and disadvantages and is therefore implemented according to the need. Since an Array is a common and widely used data structure, therefore, at times there arises a situation where the conversion of any data structure to an Array is required. For instance, this write-up specifically demonstrates the list-to-array conversion in Java.
Before directly moving to the topic of converting a list to an array, we will understand what are lists and arrays in Java and then the conversion of a list to an array.
List Data Structure in Java
A list in Java is used to store an ordered collection of data. The elements in the list are stored in such a way that insertion, deletion, and updation along with other operations are done based on the index. The collection framework is used by the list interface of Java to implement the list. Multiple operations and functions are performed on the list as per the needs of the program.
What is an Array in Java?
The arrays in Java are one of the most important aspects when declaring multiple values while coding. The arrays use a single variable to store multiple values. Hence it is also referred to as the “collection of similar types of data”. For example, an array of integers can be declared and the sum can be calculated instead of declaring each integer in a separate value.
Now let us move to the main part of the article which is converting a list to an array in Java.
Convert the List to an Array in Java
A list can be converted to an array in Java by keeping the place of the elements in the array the same as that in the declared list. The different methods to convert the list to an array include the get() method, stream() method, and toArray() method. These methods are effective in converting the specified List to an array in Java.
Method 1: Using the get() Method of Java
The get() method returns the total number of elements present at the specific index in the list. Therefore, this method fetches the elements and prints an array of elements depicted in the code below.
import java.io.*;
import java.util.*;
//Declare the class accordingly
class ConvertExample1 {
public static void main(String[] args)
{
//Create a LinkedList that contains strings
List<String> newlist = new LinkedList<String>();
//Add the elements accordingly
newlist.add("This");
newlist.add("code");
newlist.add("converts");
newlist.add("List");
newlist.add("into");
newlist.add("Array");
System.out.print("THE LIST IS: " +newlist);
// Storing it inside the array of strings
String[] arr1 = new String[newlist.size()];
//Conversion of List to array
for (int x = 0; x < newlist.size(); x++)
arr1[x] = newlist.get(x);
System.out.print("THE CONVERSION FROM LIST TO ARRAY IS: ");
// Printing elements of the array
for (String a: arr1)
System.out.print( a + " ");
}
}
In the above code block
- The required packages are imported.
- In the main() method of Java, an object “newlist” is created to declare a List.
- The elements of the List are printed using the println() method.
- In the next step, a for loop is used with the get() method to iterate over the elements of the List and copy them to the “arr1” array.
- The last step involves printing the array converted from the specified list.
Output
In the output attached below, the original list and the conversion of the list to an array are printed.

Method 2: Using Stream Introduced in Java 8
The Stream API in Java offers multiple methods to obtain the desired result. The toArray() method of Java returns the elements to the array along with the Stream API that is implemented in the code below.
import java.io.*;
import java.util.*;
//Declare the class accordingly
class ConvertExample2 {
public static void main(String[] args)
{
//Create a LinkedList that contains strings
List<String> newlist = new LinkedList<String>();
//Add the elements accordingly
newlist.add("This");
newlist.add("code");
newlist.add("converts");
newlist.add("List");
newlist.add("into");
newlist.add("Array");
System.out.print("THE LIST IS: " +newlist);
//Conversion of List to array
int i = newlist.size();
String[] arr1= newlist.stream().toArray(String[] ::new);
System.out.print("THE CONVERSION FROM LIST TO ARRAY IS: ");
// Printing elements of the array
for (String a: arr1)
System.out.print( a + " ");
}
}
Here,
- The above code implements Stream API with the toArray() method to convert the list into an array in Java.
- The “stream()” method first converts the given list into a stream and then the toArray() function converts the stream to an array.
Output
The output below shows that the converted array of Strings is printed as the output.

Method 3: Using the toArray() Method in Java
Another method of converting the list to an array is through the toArray() method of Java which returns an array of elements from the specified list. The place of each element declared in the array is the same as that of a list. The code below implements the method and prints the results accordingly.
import java.io.*;
import java.util.*;
//Declare the class accordingly
class ConvertExample3 {
public static void main(String[] args)
{
//Create a LinkedList that contains strings
List<Integer> newlist = new LinkedList<Integer>();
//Add the elements accordingly
newlist.add(12);
newlist.add(13);
newlist.add(14);
newlist.add(15);
System.out.print("THE LIST IS: " +newlist);
//Conversion of List to array
Integer[] arr2 = new Integer[newlist.size()];
arr2 = newlist.toArray(arr2);
System.out.print("THE CONVERTED ARRAY IS: ");
for(Integer x : arr2)
System.out.println(x);
}
}
In the above code block
- A list of Integers is declared as “newlist”.
- The integers are added to the list using the add() method.
- In the next step, the toArray() method converts the list of integers to an array.
- The converted array is printed accordingly.
Output
In the below output, the list with the integer values 12, 13, 14, and 15 are printed with square brackets whereas the converted array is printed as per the format of array in Java.

This concludes the implementation of different methods to convert the list to an array in Java.
Bonus Tip: Converting Back the Array to the List in Java
The asList() method of the Array class in Java returns a fixed-size list as depicted in the code below.
import java.io.*;
import java.util.*;
//Declare the class accordingly
class ConvertExample {
public static void main(String[] args)
{
//Create a LinkedList that contains strings
List<Integer> newlist = new LinkedList<Integer>();
//Add the elements accordingly
newlist.add(12);
newlist.add(13);
newlist.add(14);
newlist.add(15);
System.out.println("THE LIST IS: " +newlist);
//Conversion of array to list
Integer[] arr2 = new Integer[newlist.size()];
arr2 = newlist.toArray(arr2);
List<Integer> list = Arrays.asList(arr2);
System.out.println("Convert Array Back to List: " +list);
}
}
In the above code block:
- The asList() method is implemented to convert the Array back to a list in Java.
- The println() method returns an array of the fixed size keeping the values declared in the list at the original position.
Output
The output below shows that the declared array is converted back to a list and the elements are printed accordingly.

Conclusion
There are three different methods to convert the list to an array in Java that are the get() method, the toArray() method, and the Stream API. The converted array retains the positions of the elements when the conversion takes place from list to array in Java. This article utilized different methods to transform the list to an array in Java.