It represents a last-in, first-out collection of objects. It is used when you need a last-in, first-out access of items. When you add an item in the list, it is called pushing the item, and when you remove it, it is called popping the item.
Properties and Methods of the Stack Class
The following table lists some of the commonly used properties of the Stackclass:
|Count||Gets the number of elements contained in the Stack.|
The following table lists some of the commonly used methods of the Stackclass:
|S.N||Method Name & Purpose|
|1||Public Overridable Sub Clear
Removes all elements from the Stack.
|2||Public Overridable Function Contains (obj As Object) As Boolean
Determines whether an element is in the Stack.
|3||Public Overridable Function Peek As Object
Returns the object at the top of the Stack without removing it.
|4||Public Overridable Function Pop As Object
Removes and returns the object at the top of the Stack.
|5||Public Overridable Sub Push (obj As Object)
Inserts an object at the top of the Stack.
|6||Public Overridable Function ToArray As Object()
Copies the Stack to a new array.
In addition to the above properties of Stack class you can also check the following demo using stack class.
When the above code is compiled and executed, it produces the following result: