1import java.util.ArrayList;
2public class ArrayListRemoveAllExample
3{
4 public static void main(String[] args)
5 {
6 try
7 {
8 ArrayList<Integer> al1 = new ArrayList<Integer>();
9 al1.add(2);
10 al1.add(4);
11 al1.add(6);
12 al1.add(8);
13 al1.add(10);
14 System.out.println("ArrayList before using removeAll() method: " + al1);
15 // create another ArrayList
16 ArrayList<Integer> al2 = new ArrayList<Integer>();
17 al2.add(2);
18 al2.add(4);
19 al2.add(6);
20 // print al2
21 System.out.println("Elements to be removed: " + al2);
22 // remove elements from ArrayList using removeAll() method
23 al1.removeAll(al2);
24 // print al1
25 System.out.println("ArrayList after using removeAll() method: " + al1);
26 }
27 catch(NullPointerException ex)
28 {
29 System.out.println("Exception: " + ex);
30 }
31 }
32}