Vector(Legacy class)
The underlying data structure is resizable array or growable array.
Insertion order is preserved.
Duplicate objects are allowed.
Heterogeneous objects are allowed.
Null insertion is possible.
It implements Serializable, Cloneable and RandomAccess.
Every method present in the vector is synchronized hence vector object is thread safe.
Program
import java.util.*;
public class VectorDemo1 {
public static void main(String[] args) {
Vector v=new Vector();
System.out.println(v.capacity());
v.addElement("A");
System.out.println(v.capacity());
System.out.println(v);
for (int i = 1; i <= 10; i++)
{
v.addElement(i*10);
}
System.out.println(v);
System.out.println("New Capacity: "+v.capacity());
}
}
O/P
10
10
[A]
[A, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
New Capacity: 20