Java Convert Array to ArrayList

Tags: Array ArrayList

In this Java core tutorial we learn how to convert an array to a java.util.ArrayList object in Java programing language.

How to convert Array to ArrayList in Java

In Java, with a given array we can use the Array.asList(T… a) method to create a List object and then use ArrayList(Collection<? extends E> c) constructor to instantiate a new ArrayList object as the following Java code.

ConvertArrayToArrayListExample1.java

import java.util.ArrayList;
import java.util.Arrays;

public class ConvertArrayToArrayListExample1 {
    public static void main(String... args) {
        String[] arrayOfString = new String[3];
        arrayOfString[0] = "Java";
        arrayOfString[1] = "Kotlin";
        arrayOfString[2] = "Groovy";

        // Convert array to ArrayList object
        ArrayList<String> arrayList = new ArrayList<>(Arrays.asList(arrayOfString));

        System.out.println("ArrayList: " + arrayList);
    }
}
The output as below.
ArrayList: [Java, Kotlin, Groovy]

Happy Coding 😊

Java Insert Element to ArrayList at Specified Index

Java Get Minimum Value in ArrayList

How to Traverse ArrayList using Iterator in Java

How to Traverse ArrayList using for each loop in Java

How to Traverse ArrayList using forEach() method in Java

Java Add Element to ArrayList

Java Convert ArrayList to LinkedList

Java Convert ArrayList to Array

Java Convert ArrayList to String

Java Convert ArrayList to Comma Separated String

Java Convert ArrayList to HashSet

Convert Array to List in Java

Java Create New Array with Class Type and Length

Java Create ArrayList using List Interface

Java Get Index of Minimum Value in ArrayList

How to use Java ArrayList with Examples