add array elements to arraylist java code example
Example 1: Create ArrayList from array java
new ArrayList<>(Arrays.asList(array));
Example 2: java array to arraylist
List list = Arrays.asList(array);
Example 3: Create ArrayList from array java
new ArrayList<>(Arrays.asList(array))
Example 4: how to add to an arraylist java
import java.util.ArrayList;
public class Details {
public static void main(String[] args) {
//ArrayList Declaration
ArrayList al= new ArrayList();
//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 5: java arraylist add
//create ArrayList
ArrayList arrayList = new ArrayList();
//add item to ArrayList
arrayList.add("item");
//check if ArrayList contains item (returns boolean)
System.out.println(arrayList.contains("item"));
//remove item from ArrayList
arrayList.remove("item");