Online Java Compiler By
JavaTpoint.com
import java.util.Vector; public class VectorRemoveAllElementsExample2 { public static void main(String arg[]) { //Create an empty Vector with initial capacity of 5 Vector
vecObject = new Vector
(5); //Add values in the vector vecObject.add(3); vecObject.add(5); vecObject.add(2); vecObject.add(4); vecObject.add(1); System.out.println("Elements of Vector is: "+vecObject); //removeAllElements from the vector vecObject.removeAllElements(); //Display the vector elements System.out.println("Elements of Vector after removeAllElements(): "+vecObject); System.out.println("Size of Vector after removeAllElements() method: "+vecObject.size()); } }
Output