Vector class add(E e)method example
Appends the specified element to the end of this Vector.
Vector class add(E e)method example. This example shows you how to use add(E e)method.This method Appends the specified element to the end of this Vector.
Here is the code:-
/*
* @Program that Appends the specified element to the end of this Vector.
* Add.java
* Author:-RoseIndia Team
* Date:-24-May-2008
*/
import java.util.*;
public class Add {
public static void main(String[] args) {
//Constructs a vector
Vector V=new Vector();
//Adds the specified element to the end of this Vector.
boolean b=V.add("Girish");
V.add("Komal");
V.add("Vikas");
V.add("Mahendra");
System.out.println("Elements Added Successfully : "+b);
//Constructs a Enumeration Interface.Enumeration interface generates a series
//of elements, one at a time
Enumeration Enum = V.elements();
while (Enum.hasMoreElements())
{
//Displays the contents of vector
System.out.println(Enum.nextElement());
}
}
} |
Output of the program:-
Elements Added Successfully : true
Girish
Komal
Vikas
Mahendra |
|