Open In App

Vector removeAll() Method in Java

Last Updated : 11 Jul, 2025
Comments
Improve
Suggest changes
1 Like
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: 

Output:
Vector: [Geeks, for, Geeks, 10, 20]
Collection removed
Final Vector: [10, 20]

Program 2: 

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).


Similar Reads