Tutorial: Learn how to use the ArrayList constructor to transform an array into an ArrayList now! 🔋
In this instructional we’ll detail how to convert a Java array into a mutable instance of java.util.List using the java.util.ArrayList constructor — see the parent article regarding how to convert an array to an ArrayList in Java, which has other options for solving this problem.
Java ArrayList Constructor TOC
This is the easiest example and maybe even the most frequent way of approaching this issue since we can write this on one line if we so desire.
If we want to add a new element to this List instance, we’ll need to turn it into an instance of some other implementation of the List specification, one which is resizable, and we use a java.util.ArrayList as it fits this description.
This article was updated on March 21, 2025.
Tutorial Prerequisite Reading
Note that prerequisite reading includes the guide that covers the Arrays.asList method in Java.
So how do we pass an array literal to the java.util.ArrayList constructor?
The answer is that we can’t do this.
The ArrayList constructor option that we can use directly for this step is the one that takes an instance of a Java Collection, which is shown in the image below, and the Arrays.asList method can be used to quickly perform this step.
In the next section we’ll review the steps required to convert an array to an ArrayList using the constructor that takes an instance of java.util.Collection.
Step-by-step instructions regarding how to convert an array into an ArrayList using the ArrayList constructor
In this section we’ll cover in detail how to transform an array of Integers into a mutable instance of Java ArrayList via the java.util.ArrayList constructor.Step One (prerequisite reading): Import and use the asList static method.
We need to convert the numbers array of Integers into an instance of Arrays$ArrayList — we do so using the Arrays.asList method, which is covered as a prerequisite to this article.
We can see the importation and use of the asList static method in the image below.
This is covered in detail in the prerequisite reading for this tutorial.
Step Two: Import the Java ArraysList class.
As stated, in this step we need to import the java.util.ArrayList class.
The Java 8 ArrayList is a mutable implementation of the List interface and hence it allows for the addition and removal of elements.
Step Three: Instantiate the ArrayList with the immutableResult.
We pass the immutableResult list in as a parameter to the Java ArraysList constructor.
Step Four: Create a random Integer object.
In this step we create a random java.lang.Integer object for testing purposes.
Step Five: Add the random Integer to the mutableResult.
Add the random java.lang.Integer instance to the mutableResult instance.
This optional step demonstrates that the mutableResult List implementation can be changed and no exception will be thrown when attempting to modify it.
Step Seven: Confirm that the nextRandomInteger matches the lastElement value.
In this optional step we’re going to check that the Integer value added to the mutableResult in step five matches the expected value.
Step Eight: Visually confirm the last element matches the nextRandomInteger value.
In the last step we visually inspect and confirm that the mutableResult is of type java.util.ArrayList and that the last element in the mutableResult List is equal to that of the nextRandomInteger, which we created in step four.
We can run the constructor Java array and ArrayList example directly from our browser using the tio.run online interpreter.
Full Example
This section includes a copy of the Groovy code used to convert an array into an ArrayList.
This example script can be found as a gist on GitHub.
This example Groovy script relies on Java 8 API and it should be easy enough to convert this example into a pure Java program.
import static java.util.Arrays.asList
import java.util.List
import java.util.ArrayList
import java.util.Arrays
import java.util.Random
Random random = new Random()
int arrayCapacity = 10000
def numbers = new java.lang.Integer[arrayCapacity + 1]
for (int ctr in 0..arrayCapacity)
numbers[ctr] = java.lang.Integer.valueOf (random.nextInt())
List immutableResult = asList (numbers)
List mutableResult = new ArrayList<> (immutableResult)
println "mutableResult.class: ${mutableResult.class}, size: ${mutableResult.size ()}, first five values: "
for (int ctr in 0..5)
println "\t* ${mutableResult.get(ctr)}"
return;
Fractional CTO Services
About This Guide
This instructional is a content experiment based on research from the StackOverflow post entitled How to convert int[] into List<Integer> in Java? along with some observations discovered while doing keyword research using SEMrush.See Also
- Tutorial: Learn How To Convert An Array Into An ArrayList In Java!
- A simple example demonstrating how to call the ArrayList Constructor With an Array and with the asList method.
- Tutorial explaining how to use the Guava Lists newArrayList method to convert an array into an instance of ArrayList in Java.
- Java array to Java stream collect to an ArrayList and done!
- The H2 Database Spring Boot deep dive.
- The Spring Boot PostgreSQL deep dive.
- Learn how to open the H2 Database in a browser here.
- The Java Programming Language Introduction pillar page.











