Stack elements() method in Java with Example
The Java.util.Stack.elements() method of Stack class in Java is used to get the enumeration of the values present in the Stack.
Enumeration enu = Stack.elements()
Parameters: The method does not take any parameters.
Return value: The method returns an enumeration of the values of the Stack.
Below programs are used to illustrate the working of the java.util.Stack.elements() method:
The Stack is: [Geeks, 4, Geeks, Welcomes, You] The enumeration of values are: Geeks 4 Geeks Welcomes You
Program 2 :
The Stack is: [10, 15, 20, 25, 30] The enumeration of values are: 10 15 20 25 30
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. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.