Vector class in java.util: constructor types, protected members: capacityIncrement, elementCount, elementData

Vector class is used to implement a synchronized dynamic array in java.util. Vectors are created with a default size. When that size is reached, and if you wish to add more elements, space is automatically allocated to the vector. This space is more than the elements you are storing because vector saves time in allocating memory many times. It allocates memory in one shot. The memory for allocation is calculated by increment which you provide. If there is no increment specified by you then the memory of a vector gets doubled by each allocation.

Types of constructors used by a Vector class:

Type-1: To create a default vector.

Vector( )

Type-2: To create a vector with size.

Vector(int size)

Type-3: To create a vector with size and increment.

Vector(int size, int inc)

Type-4: To create a vector with elements of a collection.

Vector(Collection cl)

Data members defined by a vector:

capacityIncrement: It is used to store the increment value. It is a protected member.


int capacityIncrement;

elementCount: It is used to determine the number of elements currently in the vector. It is a protected member.


int elementCount;

elementData: It is an array which holds the vector. It is a protected member.


Object elementData[ ];

Leave a Reply