import java.util.*;

class VectorDemo

{

public static void main(String args[])

{

Vector v=new Vector(4,2);

System.out.println("Initial size=" +v.size());

System.out.println("Initial capacity=" +v.capacity());

v.addElement(new Integer(1));

v.addElement(new Integer(2));

v.addElement(new Float(3.0f));

v.addElement(new Float(4.1f));

v.addElement("hello");

v.addElement("world");

System.out.println("capacity after 5 addn" +v.capacity());

v.addElement(new Integer(5));

v.addElement(new Double(5.25));

System.out.println("current capacity " +v.capacity());

System.out.println("first element " +v.firstElement());

System.out.println("last element " +v.lastElement());

System.out.println("calliing removeElement(int index) " );

v.removeElement(4);

System.out.println("after removing  vector at 4 new vector is " +v);

System.out.println("calling indexOf(data)");

System.out.println("index is " +v.indexOf(3.0f));

System.out.println("vector is"+v);

System.out.println("calling contains");

if(v.contains(new Double(5.25)))

System.out.println("5.25 is present");

else

System.out.println("5.25 is not present");

 

 

Enumeration vEnum=v.elements();

System.out.println("elements in vector");

while(vEnum.hasMoreElements())

System.out.println(vEnum.nextElement()+" ");

System.out.println();

}

}

 

OUTPUT

C:\z>java VectorDemo

Initial size=0

Initial capacity=4

capacity after 5 addn6

current capacity 8

first element 1

last element 5.25

calliing removeElement(int index)

after removing  vector at 4 new vector is [1, 2, 3.0, 4.1, hello, world, 5, 5.25

]

calling indexOf(data)

index is 2

vector is[1, 2, 3.0, 4.1, hello, world, 5, 5.25]

calling contains

5.25 is present

elements in vector

1

2

3.0

4.1

hello

world

5

5.25