Listmaking it a member of the Java Collections Framework. Unlike the new collection implementations, Vector is synchronized. If a thread-safe implementation is not needed, it is recommended to use in
ArrayListplace of Vector
Introduction of Vector
- The underlying data structure is a resizable array.
- Duplicates are allowed.
- Insertion order preserved.
- Null insertion is possible.
- Heterogeneous objects are allowed.
- It implements serializable, clonable and RandomAccess Interface.
- Most of the methods are synchronized hence vector objects are thread safe.
- It is the best choice if our frequent operation is the retrieval of data.
Methods of vector:
For the better layout, look in desktop mode.
- For adding objects
Add(Object o); — from collection
Add(int index, Object o); — from list
addElement(Object o); — from vector
- For accessing elements
Object get(int index) — from collection
Object elementAt(int index) — from vector
Object FirstElement() — from vector
Object LastElement() — from vector
- Other methods
Constructors in vector:
Vector v = new vector()
Creates an empty vector with default initial capacity 10.
New capacity = 2 * current capacity.
Vector v = new vector(int initial_size);
Constructs an empty vector with the specified initial capacity and with its capacity increment equal to zero.
Vector v = new vector(int initial_size , int incrementalCapacity);
Constructs an empty vector with the specified initial capacity and capacity increment.
Vector v = new vector(Collection c);
Constructs a vector containing the elements of the specified collection, in the order, they are returned by the collection’s iterator.
For more – Read the official documentation