Tutorial: Learn how to convert an array to an ArrayList in Java Using Google Guava!
Here we have another instructional from the parent article regarding how to convert an Array to an ArrayList in Java — in this introductory Java example we will use the Google Guava library newArrayList static method, which is found on the Lists class.
Guava Lists.newArrayList Tutorial TOC
If your project is using the Google Guava core libraries for the Java Programming Language then it’s possible to convert an array to an instance of java.util.List in Java in a single line using the newArrayList method (here’s a direct link to the Guava newArrayList method source code on GitHub), and we demonstrate how this is done in this example.
This article was updated on March 11, 2025 .
The Google Guava com.google.common.collect.Lists newArrayLists Complete Example Script
Below I’ve included the Google Guava Lists newArrayList example script which we will be referring to in the step-by-step breakdown in the following section.
@Grapes(
@Grab(group='com.google.guava', module='guava', version='32.1.3-jre')
)
import static com.google.common.collect.Lists.newArrayList
def numbers = [1, 2, 3, 4, 5] as int[]
def result = newArrayList (numbers)
println "numbers.class: ${numbers.class.name}, result.class: ${result.class.name}, result: $result"
return;
Due to security constraints we are unable to run this example using tio.run so as an alternative I’ve executed this code locally using the groovyConsole.
Example regarding how to create an ArrayList using the Google Guava Lists.newArrayList method
In this section we’ll provide a step-by-step instructions regarding how to use the Google Guava List.newArrayList method to convert an array of integers into an instance of java.util.ArrayList.
We’re going to need to acquire the Google Guava dependency and on the right I have added a link to the MvnRepository page where these details can be found.
The Groovy Script example that we’re covering here should be fairly straightforward to adapt to a pure Java application if need be.
The gist regarding how to convert array to list java example is available on GitHub.
We’ll cover each of the steps in the code below and describe what’s happening.
Step One: Include the Google Guava dependency
We need to include the Google Guava dependency and this happens via the Groovy Grape dependency management declaration on lines #1-3 below.
@Grapes(
@Grab(group='com.google.guava', module='guava', version='32.1.3-jre')
)
Step Two: Import the newArrayList static method.
Import the Google Guava Lists newArrayList static method as follows:
import static com.google.common.collect.Lists.newArrayList
See line #4 in the example script below.
Step Three: Create an array containing some example data.
We need some example data to work with, and in this case an array of primitive integers should suffice.
Note that using primitive integers is fine for a small example such as what we have here however for an application that processes substantial data using primitive values will result in autoboxing on line #8 and autoboxing can wreck Java application performance if we’re not careful.
def numbers = [1, 2, 3, 4, 5] as int[]
See line #6 in the example script below.
Step Four: Convert the array to an ArrayList using the newArrayList method.
In this step we invoke the newArrayList static method and pass it the numbers array.
The newArrayList static method will return an instance of java.util.ArrayList which in this example is assigned to the result variable.
def result = newArrayList (numbers)
See line #8 in the example script below.
Step Five: Inspect the results variable.
We inspect the results variable by checking the class name of the variable, which should be an instance of java.util.ArrayList, and then printing the contents, which should include the sample data.
println "numbers.class: ${numbers.class.name}, result.class: ${result.class.name}, result: $result"
See line #10 in the example script below.
Lower in the image we can see the output includes the class name of the result variable, which is java.util.ArrayList, and the contents appear to be correct as well.
Step Six: Run the script and inspect the output.
In the last step we run the script and then inspect the output and confirm that we now have an instance of java.util.ArrayList which contains the sample data values from the numbers array declared on line #6.
This concludes the step-by-step instructions regarding how to use the Lists.newArrayList method in the Google Guava library.
Consider refactoring calls to the newArrayList method in the Guava Lists class
While developing the Google Guava lists.newArrayList example for this article I came across the following comment for the newArrayList in the Guava Lists class:
This method is not actually very useful and will likely be deprecated in the future.
Given this comment it may make sense to prioritize the refactoring of calls to the newArrayList method in projects which rely on the Google Guava framework.
About This Tutorial
This instructional is based on research from the StackOverflow post entitled How to convert int[] into List<Integer> in Java?











