arraylist retainall code example
Example: ArrayList retainAll(Collection c) method in java
import java.util.ArrayList;
public class ArrayListRetainAllMethod
{
public static void main(String[] args)
{
ArrayList<String> al1 = new ArrayList<String>();
al1.add("red");
al1.add("blue");
al1.add("green");
ArrayList<String> al2 = new ArrayList<String>();
al2.add("red");
al2.add("green");
al2.add("indigo");
al2.add("yellow");
System.out.println("ArrayList 1: " + al1);
System.out.println("ArrayList 2: " + al2);
al2.retainAll(al1);
System.out.println("After Applying retainAll() method to al2: ");
System.out.println("ArrayList 1: " + al1);
System.out.println("ArrayList 2: " + al2);
}
}