Array to ArrayList Conversion in Java Last Updated : 02 Apr, 2025 Comments Improve Suggest changes Like Article Like Report In Java, arrays are fixed-sized, whereas ArrayLists are part of the Java collection Framework and are dynamic in nature. Converting an array to an ArrayList is a very common task and there are several ways to achieve it.Methods to Convert Array to an ArrayList1. Using add() Method to Manually add the Array elements in the ArrayListThe easiest way to convert an array to an ArrayList is by manually adding elements one by one. This approach involves creating a new ArrayList and using the add() method to insert each element from the array.Example: Java // Java program to illustrate conversion // of an array to an ArrayList import java.util.ArrayList; public class Geeks { public static void convertUsingAdd(int[] arr) { ArrayList<Integer> al = new ArrayList<>(); // Manually adding array elements to the ArrayList for (int i = 0; i < arr.length; i++) { al.add(arr[i]); } System.out.println(al); } public static void main(String[] args) { int[] arr = {1, 2, 3, 4, 5}; convertUsingAdd(arr); } } Output[1, 2, 3, 4, 5] 2. Using Arrays.asList() Method of java.utils.Arrays ClassThe most efficient approach for converting Arrays to List is by using Arrays.asList() method. This method returns a fixed-size list backed by the specified array, which we can then pass to the constructor of an ArrayList.Example: Java // Java program to illustrate conversion // of an array to an ArrayList import java.util.ArrayList; import java.util.Arrays; public class Geeks { public static void convertUsingAsList(Integer[] arr) { ArrayList<Integer> al = new ArrayList<>(Arrays.asList(arr)); System.out.println(al); } public static void main(String[] args) { Integer[] arr = {1, 2, 3, 4, 5}; convertUsingAsList(arr); } } Output[1, 2, 3, 4, 5] 3. Using Collections.addAll() Method of java.utils.Collections ClassCollections.addAll() is the efficient way to convert an array to an ArrayList. This method allows us to insert an array's element directly into a collection.Example: Java // Java program to illustrate conversion // of an array to an ArrayList import java.util.ArrayList; import java.util.Collections; public class Geeks{ public static void convertUsingAddAll(String[] arr) { ArrayList<String> al = new ArrayList<>(); Collections.addAll(al, arr); System.out.println(al); } public static void main(String[] args) { String[] arr = {"A", "B", "C", "D"}; convertUsingAddAll(arr); } } Output[A, B, C, D] 4. Using Arrays.stream() and Collectors.toList() From Java 8, with the help of streams we can convert an array to a ArrayList. The Arrays.stream() methods creates a stream from the array and the Collectors.toList() collects the stream elements into a list.Example: Java // Java program to illustrate conversion // of an array to an ArrayList import java.util.ArrayList; import java.util.Arrays; import java.util.stream.Collectors; public class Geeks { public static void convertUsingStream(String[] arr) { ArrayList<String> al = (ArrayList<String>) Arrays.stream(arr) .collect(Collectors.toList()); System.out.println(al); } public static void main(String[] args) { String[] arr = {"Java", "Python", "C++"}; convertUsingStream(arr); } } Output[Java, Python, C++] 5. Using List.of(Elements) Method of java.utils.List InterfaceFrom Java 9, we can use the List.of() method to create an immutable list from an array. This method is simple and clean but note that the resulting list is immutable, so you cannot modify it.Syntax: static {T} List{T} of(a)Parameters: The method accepts a mandatory parameter ‘a’ which is the array to be converted and T signifies the list’s element type(this can be omitted).Returns: The method returns a list containing the specified elements.Exception(s): The method throws a NullPointerException if the array is null.Example: Java // Java program to illustrate conversion // of an array to an ArrayList import java.util.ArrayList; import java.util.List; public class Geeks{ public static void convertUsingListOf(String[] arr) { ArrayList<String> al = new ArrayList<>(List.of(arr)); System.out.println(al); } public static void main(String[] args) { String[] arr = {"Geek1", "Geek2", "Geek3"}; convertUsingListOf(arr); } } Output[Geek1, Geek2, Geek3] Comment More infoAdvertise with us Next Article Array to ArrayList Conversion in Java S SouravAChowdhury_97 Follow Improve Article Tags : Java Java-Collections Java - util package Arrays Java-Arrays Java-ArrayList Java-Array-Programs Java-List-Programs +4 More Practice Tags : ArraysJavaJava-Collections Similar Reads Conversion of Array To ArrayList in Java Following methods can be used for converting Array To ArrayList: Method 1: Using Arrays.asList() method Syntax: public static List asList(T... a) // Returns a fixed-size List as of size of given array. // Element Type of List is of same as type of array element type. // It returns an List containing 5 min read Array of ArrayList in Java We often come across 2D arrays where most of the part in the array is empty. Since space is a huge problem, we try different things to reduce the space. One such solution is to use jagged array when we know the length of each row in the array, but the problem arises when we do not specifically know 2 min read Array vs ArrayList in Java In Java, an Array is a fixed-sized, homogenous data structure that stores elements of the same type whereas, ArrayList is a dynamic-size, part of the Java Collections Framework and is used for storing objects with built-in methods for manipulation. The main difference between array and ArrayList is: 4 min read Convert Vector to ArrayList in Java There are multiple ways to convert vector to ArrayList, using passing the Vector in ArrayList constructor and by using simple vector traversal and adding values to ArrayList. Approach 1: Create a Vector.Add some values in Vector.Create a new ArrayList.Traverse vector from the left side to the right 3 min read How to Convert HashMap to ArrayList in Java? In Java a HashMap is a collection that stores key-value pairs on the other hand, an ArrayList is a collection that stores dynamic arrays. There are some scenarios where we need to convert a HashMap into an ArrayList such as:Extracting only the keys or values in the list form.Converting key-value pai 2 min read Convert List to Array in Java The List interface provides a way to store the ordered collection. It is a child interface of Collection. It is an ordered collection of objects where duplicate values can be stored. Since List preserves the insertion order, it allows positional access and insertion of elements. Now here we are give 5 min read Custom ArrayList in Java Before proceeding further let us quickly revise the concept of the arrays and ArrayList quickly. So in java, we have seen arrays are linear data structures providing functionality to add elements in a continuous manner in memory address space whereas ArrayList is a class belonging to the Collection 8 min read Join two ArrayLists in Java Given two ArrayLists in Java, the task is to join these ArrayLists. Examples:Input: ArrayList1: [Geeks, For, ForGeeks] , ArrayList2: [GeeksForGeeks, A computer portal] Output: [Geeks, For, ForGeeks, GeeksForGeeks, A computer portal] Input: ArrayList1: [G, e, e, k, s] , ArrayList2: [F, o, r, G, e, e, 1 min read Initialize an ArrayList in Java ArrayList is a part of the collection framework and is present in java.util package. It provides us dynamic arrays in Java. Though it may be slower than standard arrays, but can be helpful in programs where lots of manipulation in the array is needed.ArrayList inherits the AbstractList class and imp 4 min read How to Convert Vector to Array in Java? As we all know an array is a group of liked-typed variables that are referred to by a common name while on the other hand vectors basically fall in legacy classes but now it is fully compatible with collections. It is found in java.util package and implement the List interface which gives a superior 3 min read Like