Vector removeAll() Method in Java Last Updated : 24 May, 2023 Comments Improve Suggest changes Like Article Like Report The java.util.vector.removeAll(Collection col) method is used to remove all the elements from the vector, present in the collection specified. Syntax: Vector.removeAll(Collection col) Parameters: This method accepts a mandatory parameter col which is the collection whose elements are to be removed from the vector. Return Value: This method returns true if the vector is altered due to the operation at all, else False. Exception: The method throws NullPointerException if the specified collection is null. Below programs illustrate the Java.util.Vector.removeAll(Collection col) method: Program 1: Java // Java code to illustrate removeAll() 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 in the Vector vec_tor.add("Geeks"); vec_tor.add("for"); vec_tor.add("Geeks"); vec_tor.add("10"); vec_tor.add("20"); // Output the Vector System.out.println("Vector: " + vec_tor); // Creating an empty Vector Vector<String> colvec_tor = new Vector<String>(); // Use add() method to add elements in the Vector colvec_tor.add("Geeks"); colvec_tor.add("for"); colvec_tor.add("Geeks"); // Remove the head using remove() boolean changed = vec_tor.removeAll(colvec_tor); // Print the result if (changed) System.out.println("Collection removed"); else System.out.println("Collection not removed"); // Print the final Vector System.out.println("Final Vector: " + vec_tor); } } Output:Vector: [Geeks, for, Geeks, 10, 20] Collection removed Final Vector: [10, 20] Program 2: Java // Java code to illustrate removeAll() 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 in the Vector vec_tor.add(1); vec_tor.add(2); vec_tor.add(3); vec_tor.add(10); vec_tor.add(20); // Output the Vector System.out.println("Vector: " + vec_tor); // Creating an empty Vector Vector<Integer> colvec_tor = new Vector<Integer>(); // Use add() method to add elements in the Vector colvec_tor.add(30); colvec_tor.add(40); colvec_tor.add(50); // Remove the head using remove() boolean changed = vec_tor.removeAll(colvec_tor); // Print the result if (changed) System.out.println("Collection removed"); else System.out.println("Collection not removed"); // Print the final Vector System.out.println("Final Vector: " + vec_tor); } } Output:Vector: [1, 2, 3, 10, 20] Collection not removed Final Vector: [1, 2, 3, 10, 20] Time complexity: O(n^2). // n is the size of the vector.Auxiliary Space: O(n). Comment More infoAdvertise with us Next Article Vector removeAll() Method in Java K kundankumarjha Follow Improve Article Tags : Misc Java Java-Collections Java - util package Java-Functions Java-Vector +2 More Practice Tags : JavaJava-CollectionsMisc Similar Reads Java Vector elements() Method In Java, the elements() method is used to return an enumeration of the elements in the Vector. This method allows you to iterate over the elements of a Vector using an Enumeration, which provides methods for checking if there are more elements and retrieving the next element.Example 1: Below is the 2 min read Vector ensureCapacity() method in Java with Example The ensureCapacity() method of Java.util.Vector class increases the capacity of this Vector instance, if necessary, to ensure that it can hold at least the number of elements specified by the minimum capacity argument. Syntax: public void ensureCapacity(int minCapacity) Parameters: This method takes 2 min read Vector equals() Method in Java The java.util.vector.equals(Object obj) method of Vector class in Java is used verify the equality of an Object with a vector and compare them. The list returns true only if both Vector contains same elements with same order. Syntax: first_vector.equals(second_vector) Parameters: This method accepts 2 min read Vector firstElement() Method in Java The java.util.vector.firstElement() method in Java is used to retrieve or fetch the first element of the Vector. It returns the element present at the 0th index of the vector Syntax: Vector.firstElement() Parameters: The method does not take any parameter. Return Value: The method returns the first 2 min read Vector forEach() method in Java The forEach() method of Vector is used to perform a given action for every element of the Iterable of Vector until all elements have been Processed by the method or an exception occurs. The operations are performed in the order of iteration if the order is specified by the method. Exceptions thrown 3 min read Vector hashCode() Method in Java The java.util.vector.hashCode() method in Java is used to get the hashcode value of this vector. Syntax: Vector.hashCode() Parameters: The method does not take any parameter. Return Value: The method returns hash code value of this Vector which is of Integer type. Below programs illustrate the Java. 2 min read Vector indexOf() Method in Java The java.util.vector.indexOf(Object element) method is used to check and find the occurrence of a particular element in the vector. If the element is present then the index of the first occurrence of the element is returned otherwise -1 is returned if the vector does not contain the element. Syntax: 3 min read Vector insertElementAt() Method in Java with Examples insertElementAt() method of Vector class present inside java.util package is used to insert a particular element at the specified index of the Vector. Both the element and the position are passed as the parameters. If an element is inserted at a specified index, then all the elements are pushed upwa 3 min read Vector isEmpty() Method in Java The Java.util.Vector.isEmpty() method in Java is used to check and verify if a Vector is empty or not. It returns True if the Vector is empty else it returns False. Syntax: Vector.isEmpty() Parameters: This method does not take any parameter. Return Value: This function returns True if the Vectoris 2 min read Vector iterator() method in Java with Examples iterator() method of Vector class that is present inside java.util package is used to return an iterator of the same elements as that of the Vector. The elements are returned in random order from what was present in the vector. Syntax: Iterator iterate_value = Vector.iterator(); Parameters: The func 2 min read Like