Program - Demo of Vector Operation
Program - Demo of Vector Operation
import java.util.*;
class VectorDemo
{
public static void main(String args[ ])
{
// initial size is 4, increment is 2
Vector v = new Vector(4,2);
v.addElement(new Integer(1));
v.addElement(new Integer(2));
v.addElement(new Integer(3));
v.addElement(new Integer(4));
v.addElement(new Integer(5));
if(v.contains(new Double(5.20)))
System.out.println("Vector contains 5.20");
}
}
/*Output:
Initial size : 0
Initial Capacity : 4
Capacity after five additions : 6
Current Capacity : 6
Current Capacity : 8
Current Capacity : 10
First element :1
Last element :12
Elements in vector :
1 2 3 4 5 5.25 10.28 8 20.25 10 11 12
index of: 11 10
element at 5:5.25
Elements in vector :
1 2 3 4 5 100 5.25 10.28 8 20.25 10 11 12*/