![]() |
VOOZH | about |
The size() method of java.util.Stack is used to get the number of elements present in the stack. It does not take any parameters and returns an int representing the stack's size.
Example:
Stack: [Welcome, To, GFG] The size is: 3
Explanation:
int size()
Example: This code demonstrates how to use the size() method of the Stack class in Java to find the number of elements present in a stack of integers.
Stack: [10, 15, 30, 20, 5] The size is: 5
Explanation: stack.size() returns the total number of elements in the stack and prints it.