Last Updated : 11 Jul, 2025
In Java, the containsAll() method is used to check if the Vector contains all the elements of a specified Collection or not.
Example 1: Below program demonstrating the use of containsAll() method with Strings.
Java
// Java Program to demonstrate the use of
// containsAll() with Strings
import java.util.*;
public class Geeks {
public static void main(String args[])
{
// Creating an empty Vector
Vector<String> v = new Vector<String>();
// Use add() method to add
// elements into the Vector
v.add("Welcome");
v.add("To");
v.add("Geeks");
v.add("4");
v.add("Geeks");
// Displaying the Vector
System.out.println("" + v);
// Creating another empty Vector
Vector<String> nv = new Vector<String>();
nv.add("Geeks");
nv.add("4");
nv.add("Geeks");
System.out.println("Are all the contents equal: " + v.containsAll(nv));
}
}
[Welcome, To, Geeks, 4, Geeks] Are all the contents equal: trueSyntax of Vector containsAll() Method
boolean containsAll(Collection c)
Parameters: It takes collection as an input to check if all its elements are present in the vector.
Return Type:
Example 2: Below program demonstrating the use of containsAll() method with Integers.
Java
// Java Program to demonstrate the
// use of containsAll() with Integers
import java.util.*;
public class Geeks {
public static void main(String args[])
{
// Creating an empty Vector
Vector<Integer> v = new Vector<Integer>();
// Use add() method to add elements into the Vector
v.add(10);
v.add(15);
v.add(30);
v.add(20);
v.add(5);
// Displaying the Vector
System.out.println("" + v);
// Creating another empty Vector
Vector<Integer> nv = new Vector<Integer>();
nv.add(20);
nv.add(25);
nv.add(30);
System.out.println("Are all the contents equal: " + v.containsAll(nv));
}
}
[10, 15, 30, 20, 5] Are all the contents equal: false
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4