Write a Java Program to implement Vector class and its methods.

import java.lang.*;
import java.util.Vector;
import java.util.Enumeration;
class vectordemo
{
public static void main(String arg[])
{
Vector v=new Vector();
v.addElement("one");
v.addElement("two");
v.addElement("three");
v.insertElementAt("zero",0);
v.insertElementAt("oops",3);
v.insertElementAt("four",5);
System.out.println("Vector Size :"+v.size());
System.out.println("Vector apacity :"+v.capacity());
System.out.println(" The elements of a vector are :");
Enumeration e=v.elements();
while(e.hasMoreElements())

System.out.println(e.nextElement() +" ");
System.out.println();
System.out.println("The first element is : " +v.firstElement());
System.out.println("The last element is : " +v.lastElement());
System.out.println("The object oops is found at position : "+v.indexOf("oops"));
v.removeElement("oops");
v.removeElementAt(1);
System.out.println("After removing 2 elements ");
System.out.println("Vector Size :"+v.size());
System.out.println("The elements of vector are :");
for(int i=0;i<v.size();i++)
System.out.println(v.elementAt(i)+" ");
}
}


OUTPUT:-

C:\jdk1.6.0_26\bin>javac vectordemo.java
C:\jdk1.6.0_26\bin>java vectordemo
Vector Size :6
Vector apacity :10
The elements of a vector are :
zero
one
two
oops


three
four
The first element is : zero
The last element is : four
The object oops is found at position : 3
After removing 2 elements
Vector Size :4
The elements of vector are :
zero
two
three
four