Array to ArrayList | Create ArrayList from Array in Java

Conversion of Array To ArrayList in Java is the top question in one of most viewed and voted questions on StackOverflow. You can convert an array to ArrayList using the following ways.

  • Using Arrays.asList() method: Simply pass the array in method.
  • Collections.addAll() method: Create a new list and add array elements using this method to an existing list.
  • Iteration method: Create a new list and add array elements with the help of for-loop.
Conversion of Array To ArrayList in Java

Let’s Create ArrayList from array

For example, you have an array that is initialized like:

And you want to convert this array into an object of the ArrayList class.

1. Arrays.asList() method

This is The Most Popular and Accepted Answer in stackoverflow.com.

Let’s see the example of it:-

Output: [a, b, c, d, e]

Note: the size of the list returned from asList()  is fixed. if add or remove elements from the returned list, an UnsupportedOperationException will be thrown.

2. Collections.addAll() method

It seems an extra step as an upper code. But it’s not, this ArrayList is not a fixed size. You can add more elements.

Complete example code:

Output: [a, b, c, d, e]

3. Iteration method

Using a for-each loop and list add method. Loop will run for a every element in the array and then adding into a list.

Output: [a, b, c, d, e]

Do comment if you have any doubts and suggestions on this tutorial. If you know other methods to do it, then comment in below, we will update it in this tutorial.

Note: This example (Project) is developed in IntelliJ IDEA 2018.2.6 (Community Edition)
JRE: 11.0.1
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.15.1
Java version 11
All Java Array to Arraylis Example are in Java 11, so it may change on different from Java 9 or 10 or upgraded versions.


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.