PROGRAM
import java.util.*;
import java.math.*;
class Vect
{
public static void main(String arg[])
{
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(5.45));
System.out.println("Current capacity: "+v.capacity());
v.addElement(new Double(6.08));
v.addElement(new Integer(7));
System.out.println("Current capacity: "+v.capacity());
v.addElement(new Float(9.4));
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. ");
}
}
OUTPUT
Initial Size: 0
Initial capacity: 3
capacity after four additions: 5
Current capacity: 5
Current capacity: 7
Current capacity: 9
First element: 1
Last element: 12
Vector contains 3.
PROGRAM TO ILLUSTRATE VECTOR CLASS is a post from ShoutToWorld - Let's Learn Let's Shout - Helping bloggers and developers.