The ensureCapacity() method of Java.util.Vector class increases the capacity of this Vector instance, if necessary, to ensure that it can hold at least the number of elements specified by the minimum capacity argument.
public void ensureCapacity(int minCapacity)
Parameters: This method takes the desired minimum capacity as a parameter.
Below are the examples to illustrate the ensureCapacity() method.
Vector: [10, 20, 30, 40] Vector can now surely store upto 5000 elements.
Vector: [A, B, C, D] Vector can now surely store upto 400 elements.
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.