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);
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);