In vector by default initialCapacity is set at 10 and capacityIncrement is also set at 10.
Thus if we do -
Vector<String> vector = new Vector<>();
we have initialCapacity and capacityIncrement both set at 10.
However, we have the flexibility to set our own values.
For example, if we do -
Vector<String> vector = new Vector<>(5,5);
we have initialCapacity and capacityIncrement both set at 5.
Now, post initialization, we have the methods -
void setSize(int size)
void ensureCapacity(int capacity)
void trimToSize()
to change both size and capacity as per our needs.
But, how can we change the capacityIncrement value post initialization as per our need?
You can do it using reflect.Field as below: