//Demonstrate various vector operations.
import java.util.*;
class VectorDemo{
public static void main(String[] args)
{
//initial size is 3,increment is 2
Vector v = new Vector(3,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 Integer(3));
v.addElement(new Integer(4));
System.out.println("Capacity after four additions:" + v.capacity());
v.addElement(new Double(9.99));
System.out.println("Current capacity :" + v.capacity());
v.addElement(new Double(77.87));
v.addElement(new Integer(9));
System.out.println("Current capacity :" + v.capacity());
v.addElement(new Float(77.7));
v.addElement(new Integer(10));
System.out.println("Current capacity :" + v.capacity());
v.addElement(new Integer(11));
v.addElement(new Integer(12));
System.out.println("First element :" + (Integer)v.firstElement());
System.out.println("Last element :" + (Integer)v.lastElement());
if(v.contains(new Integer(3)))
System.out.println("Vector contains 3.");
//enumerate the elements in the vector
Enumeration enum = v.elements();
System.out.println("Elements in vector:");
while(enum.hasMoreElements()){
System.out.print(enum.nextElement() + " ");
}
System.out.println();
/*
//use an iterator to display contents
Iterator i = v.iterator();
System.out.println("Elements in vector:");
while(i.hasNext()){
System.out.print(i.next() + " ");
}
System.out.println();
*/
}
}