The Java.util.Vector.capacity() method in Java is used to get the capacity of the Vector or the length of the array present in the Vector.
Parameters: The method does not take any parameter.
Return Value: The method returns the capacity or the internal data array’s length present in the Vector, which is an integer value.
Below programs illustrate the Java.util.Vector.capacity() method:
Program 1: Vector with string elements.
Vector: [Welcome, To, Geeks, 4, Geeks] The capacity is: 10
Program 2: Vector with Integer elements.
Vector: [10, 15, 30, 20, 5] The capacity is: 10
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.