The Wayback Machine - https://web.archive.org/web/20240618020144/https://www.geeksforgeeks.org/vector-containsall-method-in-java/
Open In App

Vector containsAll() Method in Java

Last Updated : 17 Aug, 2018
Improve
Improve
Like Article
Like
Save
Share
Report

The java.util.vector.containsAll() method is used to check to check if this Vector contains all of the elements in the specified Collection. So basically it is used to check if a vector contains a set of elements or not.

Syntax:

Vector.containsAll(Collection col)

Parameters: This method accepts a mandatory parameter col which is of the type of vector. This is the collection whose elements are needed to be checked if it is present in the vector or not.

Return Value: The method returns True if all elements in the collection col are present in the vector otherwise it returns False.

Exception: The method throws NullPointerException if the specified collection is NULL.

Below programs illustrates the Java.util.Vector.containsAll() method:

Program 1:




// Java code to illustrate containsAll()
import java.util.*;
  
public class VectorDemo {
    public static void main(String args[])
    {
        // Creating an empty Vector
        Vector<String> vec_tor = new Vector<String>();
  
        // Use add() method to add elements into the Vector
        vec_tor.add("Welcome");
        vec_tor.add("To");
        vec_tor.add("Geeks");
        vec_tor.add("4");
        vec_tor.add("Geeks");
  
        // Displaying the Vector
        System.out.println("Vector: " + vec_tor);
  
        // Creating another empty Vector
        Vector<String> colvec_tor = new Vector<String>();
  
        colvec_tor.add("Geeks");
        colvec_tor.add("4");
        colvec_tor.add("Geeks");
  
        System.out.println("Are all the contents equal? " + vec_tor.containsAll(colvec_tor));
  
        // Creating another empty Vector
        Vector<String> colvec_tor2 = new Vector<String>();
  
        colvec_tor2.add("Hello");
        colvec_tor2.add("Geeks");
  
        System.out.println("Are all the contents equal? " + vec_tor.containsAll(colvec_tor2));
    }
}


Output:

Vector: [Welcome, To, Geeks, 4, Geeks]
Are all the contents equal? true
Are all the contents equal? false

Program 2:




// Java code to illustrate contains()
import java.util.*;
  
public class VectorDemo {
    public static void main(String args[])
    {
        // Creating an empty Vector
        Vector<Integer> vec_tor = new Vector<Integer>();
  
        // Use add() method to add elements into the Vector
        vec_tor.add(10);
        vec_tor.add(15);
        vec_tor.add(30);
        vec_tor.add(20);
        vec_tor.add(5);
  
        // Displaying the Vector
        System.out.println("Vector: " + vec_tor);
  
        // Displaying the Vector
        System.out.println("Vector: " + vec_tor);
  
        // Creating another empty Vector
        Vector<Integer> colvec_tor = new Vector<Integer>();
  
        colvec_tor.add(20);
        colvec_tor.add(25);
        colvec_tor.add(30);
  
        System.out.println("Are all the contents equal? " + vec_tor.containsAll(colvec_tor));
  
        // Creating another empty Vector
        Vector<Integer> colvec_tor2 = new Vector<Integer>();
  
        colvec_tor2.add(10);
        colvec_tor2.add(20);
  
        System.out.println("Are all the contents equal? " + vec_tor.containsAll(colvec_tor2));
    }
}


Output:

Vector: [10, 15, 30, 20, 5]
Vector: [10, 15, 30, 20, 5]
Are all the contents equal? false
Are all the contents equal? true


Previous Article
Next Article

Similar Reads

AbstractCollection containsAll() Method in Java with Examples
The containsAll() method of Java AbstractCollection is used to check whether two Collections contain the same elements or not. It takes one collection as a parameter and returns True if all of the elements of this collection is present in the other collection. Syntax: AbstractCollection.containsAll(Collection C) Parameters: The parameter C is a Col
2 min read
List containsAll() method in Java with Examples
The containsAll() method of List interface in Java is used to check if this List contains all of the elements in the specified Collection. So basically it is used to check if a List contains a set of elements or not. Syntax: boolean containsAll(Collection col) Parameters: This method accepts a mandatory parameter col which is of the type of collect
2 min read
CopyOnWriteArrayList containsAll() method in Java
The containsAll() method of CopyOnWriteArrayList class in Java is used to check if this List contains all of the elements in the specified Collection. So basically it is used to check if a List contains a set of elements or not. Syntax: boolean containsAll(Collection col) Parameters: This method accepts a mandatory parameter col which is of the typ
3 min read
Stack containsAll() method in Java with Example
The containsAll() method of Java Stack is used to check whether two stacks contain the same elements or not. It takes one stack as a parameter and returns True if all of the elements of this stack is present in the other stack. Syntax: public boolean containsAll(Collection C) Parameters: The parameter C is a Collection. This parameter refers to the
2 min read
LinkedHashSet containsAll() method in Java with Example
The containsAll() method of Java LinkedHashSet is used to check whether two sets contain the same elements or not. It takes one set as a parameter and returns True if all of the elements of this set is present in the other set. Syntax: public boolean containsAll(Collection C) Parameters: The parameter C is a Collection. This parameter refers to the
2 min read
HashSet containsAll() method in Java with Example
The containsAll() method of Java HashSet is used to check whether two sets contain the same elements or not. It takes one set as a parameter and returns True if all of the elements of this set is present in the other set. Syntax: public boolean containsAll(Collection C) Parameters: The parameter C is a Collection. This parameter refers to the set w
2 min read
AbstractSet containsAll() method in Java with Example
The containsAll() method of Java AbstractSet is used to check whether two sets contain the same elements or not. It takes one set as a parameter and returns True if all of the elements of this set is present in the other set. Syntax: public boolean containsAll(Collection C) Parameters: The parameter C is a Collection. This parameter refers to the s
2 min read
CopyOnWriteArraySet containsAll() method in Java with Example
The containsAll() method of Java CopyOnWriteArraySet is used to check whether two sets contain the same elements or not. It takes one set as a parameter and returns True if all of the elements of this set is present in the other set. Syntax: public boolean containsAll(Collection C) Parameters: The parameter C is a Collection. This parameter refers
2 min read
TreeSet containsAll() method in Java with Example
The containsAll() method of Java TreeSet is used to check whether two sets contain the same elements or not. It takes one set as a parameter and returns True if all of the elements of this set is present in the other set. Syntax: public boolean containsAll(Collection C) Parameters: The parameter C is a Collection. This parameter refers to the set w
2 min read
Set containsAll() method in Java with Examples
The containsAll() method of Java Set is used to check whether two sets contain the same elements or not. It takes one set as a parameter and returns True if all of the elements of this set is present in the other set. Syntax: public boolean containsAll(Collection C) Parameters: The parameter C is a Collection. This parameter refers to the set whose
2 min read