All Elements in Vector can be removed by clear() method. Clear() method in Vector clear Vector object and size of the Vector will become 0
Example of clear in Vector
import java.util.Vector; public class VectorClearExample { public static void main(String[] args) { Vector<String> vc=new Vector<String>(); vc.add("Vector Element 1"); vc.add("Vector Element 2"); vc.add("Vector Element 3"); vc.clear(); // clear all elements from Vector System.out.println("Vector Size :"+vc.size()); } }
Output
Vector Size :0
Tags: Collections




Link to Us