Vector class clear()method example
Removes all of the elements from this Vector.
Vector class clear()method example. This example shows you how to use clear()method.This method Removes all of the elements from this Vector.
Here is the code:-
/*
* @Program that Removes all of the elements from this Vector.
* Clear.java
* Author:-RoseIndia Team
* Date:-24-May-2008
*/
import java.util.*;
public class Clear {
public static void main(String[] args) {
//creating vector
Vector v= new Vector();
v.add("girish");
v.add("tewari");
//creating enumeration interface
Enumeration E=v.elements();
System.out.println("Element in the vector are: ");
while(E.hasMoreElements())
{
System.out.println(E.nextElement()+"\t");
}
//Removes all of the elements from this Vector.
v.clear();
System.out.println("Vector after clearing is : "+v);
}
} |
Output of the program:-
Element in the vector are:
girish
tewari
Vector after clearing is : [] |
|