how to add elements directly to a new arraylist in java code example
Example 1: 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);
Example 2: java make arraylist
//Create the Arraylist variable: . Replace the T with the type of
//data to be stored in the list.
ArrayList<T> exampleList = new ArrayList<>();
//You can now perform operations on this ArrayList