Remove all elements from vector in java

The clear() method is used to delete or remove all elements of a vector at one call in java.

Syntax:

vector.clear()

Example:

package com.w3spoint;
 
import java.util.Vector;
 
public class Test {
  public static void main(String args[]){
	Vector<String> vector = new Vector<String>();
        //adding elements to the end
	vector.add("Jai");
	vector.add("Mahesh");
	vector.add("Hemant");
	vector.add("Vishal");
	System.out.println("Actual vector:"+vector);
	vector.clear();
        System.out.println("After clear vector:"+vector);
  }
}

Output

Actual vector:[Jai, Mahesh, Hemant, Vishal]
After clear vector:[]