Stack addElement(E) method in Java with Example
The addElement(E) method of Stack Class is used to append the element passed as a parameter to this function at the end of the Stack.
boolean addElement(E obj) Here, E is the type of elements maintained by this container.
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 True if at least one action of append is performed, else False.
Below program illustrate the Java.util.Stack.addElement() method:
The Stack is: [Geeks, for, Geeks, 10, 20] The new Stack is: [Geeks, for, Geeks, 10, 20, GeeksForGeeks]
The Stack is: [10, 20, 30, 40, 50] The new Stack is: [10, 20, 30, 40, 50, 100]