Java Vector - containsAll() Method
The java.util.Vector.containsAll() method is used to check whether the vector contains all of the elements in the specified Collection or not. It returns true if the vector contains all of the elements in the specified Collection, else returns false.
Syntax
public boolean containsAll(Collection<?> c)
Parameters
c |
Specify the collection whose elements will be tested for containment in the vector. |
Return Value
Returns true if the vector contains all of the elements in the specified Collection, else returns false.
Exception
Throws NullPointerException, if the specified collection is null.
Example:
In the example below, the java.util.Vector.containsAll() method is used to check whether the vector MyVector contains all the elements of LinkedList called MyList.
import java.util.*; public class MyClass { public static void main(String[] args) { //creating a vector Vector<Integer> MyVector = new Vector<Integer>(); //populating vector MyVector.add(10); MyVector.add(20); MyVector.add(30); MyVector.add(40); //creating linkedlist LinkedList<Integer> MyList = new LinkedList<Integer>(); //populating linkedlist MyVector.add(20); MyVector.add(40); //checking the containment if(MyVector.containsAll(MyList)) System.out.println("MyVector contains all elements of MyList."); else System.out.println("MyVector does not contain all elements of MyList."); } }
The output of the above code will be:
MyVector contains all elements of MyList.
❮ Java.util - Vector