Open In App

Stack capacity() method in Java with Example

Last Updated : 24 Dec, 2018
Comments
Improve
Suggest changes
Like Article
Like
Report
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. Syntax:
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: Example 1:
Output:
The Stack is: [Geeks, for, Geeks, 10, 20]
Capacity: 10
Example 2:
Output:
The Stack is: [10, 20, 30, 40, 50]
Capacity: 10

Similar Reads