Vector containsAll() Method in Java
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)); } } |
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)); } } |
Vector: [10, 15, 30, 20, 5] Vector: [10, 15, 30, 20, 5] Are all the contents equal? false Are all the contents equal? true
Recommended Posts:
- LinkedHashSet containsAll() method in Java with Example
- TreeSet containsAll() method in Java with Example
- HashSet containsAll() method in Java with Example
- CopyOnWriteArrayList containsAll() method in Java
- Stack containsAll() method in Java with Example
- Set containsAll() method in Java with Examples
- AbstractSet containsAll() method in Java with Example
- CopyOnWriteArraySet containsAll() method in Java with Example
- List containsAll() method in Java with Examples
- AbstractCollection containsAll() Method in Java with Examples
- SortedSet containsAll() method in Java with Examples
- JavaTuples containsAll() method
- Vector contains() Method in Java
- Vector get() Method in Java
- Vector add() Method in Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.