Online Java Compiler By
JavaTpoint.com
import java.util.Vector; public class VectorRemoveAllExample1 { public static void main(String arg[]) { //Create an empty Vec1 Vector
vec1 = new Vector<>(); //Add elements in the Vector1 vec1.add(1); vec1.add(2); vec1.add(3); vec1.add(4); vec1.add(5); //Displaying the Vector elements System.out.println("Vector: " + vec1); System.out.println("Removing all the elements"); //use removeAll() method vec1.removeAll(vec1); //Display the size of the Vector System.out.println("Size of the vector: "+vec1.size()); } }
Output