Stack Class

This lesson provides some more detail on the built-in methods of the stack class in Java.

We'll cover the following

Stack

Stacks are a type of data structure with a last in first out (LIFO) order. A new element is added at the top and removed from that end only.

Some basic methods supported by stack are:


push(i) – Insert an element 'i' at the top of the stack.
 
pop() – Deletes the top most element of the stack

peek() – Returns the element at the top of the stack.

empty() – Returns whether the stack is empty or not.

size() - Returns the size or the number of elements present in the stack.

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.