VOOZH about

URL: https://www.geeksforgeeks.org/java/vector-clear-method-in-java/

⇱ Vector clear() Method in Java - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Vector clear() Method in Java

Last Updated : 12 Dec, 2024

The Java.util.Vector.clear() method is used to remove all the elements from a Vector. Using the clear() method only clears all the element from the vector and does not delete the vector. In other words, we can say that the clear() method is used to only empty an existing vector.

Syntax:

Vector.clear()

  • Parameters: The method does not take any parameter
  • Return Value: The function does not returns any value.

Example of Vector clear() Method

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

Example 1:


Output
Elements in Vector : [Welcome, To, GFG]
Vector after Operation : []

Example 2:


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


Comment