java arraylist containsall code example
Example: ArrayList containsAll(Collection c) method in java
import java.util.ArrayList;
public class ArrayListContainsAllMethodExample
{
public static void main(String[] args)
{
ArrayList<String> al1 = new ArrayList<String>();
al1.add("red");
al1.add("green");
al1.add("blue");
System.out.println("ArrayList 1: " + al1);
ArrayList<String> al2 = new ArrayList<String>();
al2.add("blue");
al2.add("green");
System.out.println("ArrayList 2: " + al2);
boolean output1 = al1.containsAll(al2);
System.out.println("Does ArrayList 1 contains all elements of ArrayList 2?: " + output1);
boolean output2 = al2.containsAll(al1);
System.out.println("Does ArrayList 2 contains all elements of ArrayList 1?: " + output2);
}
}