how to add an array into an arraylist - java code example

Example 1: java array to arraylist

List<Element> list = Arrays.asList(array);

Example 2: Create ArrayList from array java

new ArrayList<>(Arrays.asList(array))

Example 3: how to add to an arraylist java

import java.util.ArrayList;
public class Details {
    public static void main(String[] args) {

        //ArrayList<String> Declaration
        ArrayList<String> al= new ArrayList<String>();
        //add method for String ArrayList
        al.add("Ram");
        al.add("Shyam");
        al.add("CPS");
        al.add("John");
        al.add("Steve");
        System.out.println("Elements of ArrayList of String Type: "+al);

Tags:

Java Example