1ArrayList<Integer> str=new ArrayList<Integer>();
2str.add(0);
3str.add(1);
4 // Result = [0, 1]
5
6str.add(1, 11);
7 // Result = [0, 11, 1]
1ArrayList<String> arrayList = new ArrayList<>();
2// Adds element at the back of the list
3arrayList.add("foo");
4arrayList.add("bar");
5// Result = ["foo", "bar"]
6
7// Adds element at the specified index
8arrayList.add(1, "baz");
9// Result = ["foo", "baz", "bar"]
1ArrayList<String> languages = new ArrayList<String>();
2languages.add("PHP");
3languages.add("JAVA");
4languages.add("C#");
5ArrayList<int> numbers = new ArrayList<int>();
6numbers.add(9);
7numbers.add(14);
8numbers.add(2);
1//create ArrayList
2ArrayList<String> arrayList = new ArrayList<String>();
3//add item to ArrayList
4arrayList.add("item");
5//check if ArrayList contains item (returns boolean)
6System.out.println(arrayList.contains("item"));
7//remove item from ArrayList
8arrayList.remove("item");
1import java.util.ArrayList;
2public class Details {
3 public static void main(String[] args) {
4
5 //ArrayList<String> Declaration
6 ArrayList<String> al= new ArrayList<String>();
7 //add method for String ArrayList
8 al.add("Ram");
9 al.add("Shyam");
10 al.add("CPS");
11 al.add("John");
12 al.add("Steve");
13 System.out.println("Elements of ArrayList of String Type: "+al);
1public void add(int index, E element)
2// adding element 25 at third position
3arrlist.add(2,25);