VOOZH about

URL: https://www.geeksforgeeks.org/java/vector-removeallelements-method-in-java-with-example/

⇱ Vector removeAllElements() method in Java with Example - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Vector removeAllElements() method in Java with Example

Last Updated : 11 Jul, 2025

The Java.util.Vector.removeAllElements() method is used to removes all components from this Vector and sets its size to zero. Syntax:

Vector.removeAllElements()

Parameters: The method does not take any parameter 

Return Value: The function does not returns any value. 

Below programs illustrate the Java.util.Vector.removeAllElements() method. 

Example 1: 

Output:
Vector: [Welcome, To, Geeks, 4, Geeks]
The final Vector: []

Example 2: 

Output:
Vector: [10, 15, 30, 20, 5]
The final Vector: []

Time complexity: O(n). // n is the size of the vector.
Auxiliary space: O(1)

Comment