1import java.util.ArrayList;
2public class ArrayListRemoveObjectExample
3{
4 public static void main(String[] args)
5 {
6 // create an empty ArrayList
7 ArrayList<String> names = new ArrayList<String>(7);
8 names.add("Bharat");
9 names.add("Chetan");
10 names.add("Dinesh");
11 names.add("Bharat");
12 names.add("Falguna");
13 names.add("Dinesh");
14 names.add("Bharat");
15 System.out.println("ArrayList before using remove(Object o) method: ");
16 for(int a = 0; a < 7; a++)
17 {
18 System.out.println(names.get(a).toString());
19 }
20 // removing first occurrence of "Bharat" and "Dinesh"
21 names.remove("Bharat");
22 names.remove("Dinesh");
23 System.out.println("ArrayList after using remove(Object o) method: ");
24 for(int a = 0; a < 5; a++)
25 {
26 System.out.println(names.get(a).toString());
27 }
28 }
29}