add arraylist to arraylist java code example
Example 1: convert arraylist to array in java
Integer[] arr = new Integer[al.size()];
for (int i = 0; i < al.size(); i++)
arr[i] = al.get(i);
Example 2: how to add to an arraylist java
import java.util.ArrayList;
public class Details {
public static void main(String[] args) {
ArrayList<String> al= new ArrayList<String>();
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 3: java arraylist add
ArrayList<String> arrayList = new ArrayList<String>();
arrayList.add("item");
System.out.println(arrayList.contains("item"));
arrayList.remove("item");
Example 4: add two arraylist
oneList.addAll(secondList);