Open In App

Stack get() method in Java with Example

Last Updated : 24 Dec, 2018
Summarize
Comments
Improve
Suggest changes
Share
1 Like
Like
Report
The Java.util.Stack.get() method is used to fetch or retrieve an element at a specific index from a Stack. Syntax:
Stack.get(int index)
Parameters: This method accepts a mandatory parameter index which is of integer data type. It specifies the position or index of the element to be fetched from the Stack. Return Value: The method returns the element present at the position specified by the parameter index. Below programs illustrate the Java.util.Stack.get() method: Program 1:
Output:
Stack: [Geeks, for, Geeks, 10, 20]
The element is: Geeks
Program 2:
Output:
Stack: [1, 2, 3, 10, 20]
The element is: 20

Similar Reads