1import java.util.ArrayList;
2import java.util.List;
3public class Demo {
4 public static void main(String[] args) {
5 List aList = new ArrayList();
6 aList.add("A");
7 aList.add("B");
8 aList.add("C");
9 aList.add("D");
10 aList.add("E");
11 int index1 = aList.indexOf("C");
12 int index2 = aList.indexOf("Z");
13 if(index1 == -1)
14 System.out.println("The element C is not in the ArrayList");
15 else
16 System.out.println("The element C is in the ArrayList at index " + index1);
17 if(index2 == -1)
18 System.out.println("The element Z is not in the ArrayList");
19 else
20 System.out.println("The element Z is in the ArrayList at index " + index2);
21 }
22}
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");