1/11
Looks like no tags are added yet.
Stack
Models and implements a stack data structure; follows Last In First Out (LIFO)
Stack()
Default constructor that is used to create an empty stack.
Serializable
a marker interface that classes must implement if they are to be serialized and deserialized
Cloneable
An interface in Java which needs to be implemented by a class to allow its objects to be cloned
Iterable
an interface represents a collection of objects which is iterable – meaning which can be iterated
Collection<E>
Represents a group of objects known as its elements; used to pass around collections of objects were maximum generality is desired
List<E>
Provides a way to store the ordered collection; a child interface of Collection
RandomAccess
Marker interface used by List implementations to indicate that they support fast (generally constant time) random access
How to create new Stack in Java?
Import the java.util.stack package and use the Stack() constructor.
What does the push() method do?
It places an element at the top of the stack.
What is the use of the peek() method?
To retrieve an element from the stack without removing it.
What does the pop() method do?
It removes and returns the element at the top of the stack.