The capacity() method of Stack Class is used to get the capacity of this Stack. That is the number of elements present in this stack container.
public int capacity()
Parameters: This function accepts a parameter E obj which is the object to be added at the end of the Stack.
Return Value: The method returns integer value which is the capacity of the Stack
Below program illustrate the Java.util.Stack.capacity() method:
The Stack is: [Geeks, for, Geeks, 10, 20] Capacity: 10
The Stack is: [10, 20, 30, 40, 50] Capacity: 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.