Java: Stack (LIFO: Last In First Out)

Published: 13 January 2024
on channel: HowTo:
815
3

Introduction to Stack in Java.
A stack is a collection of objects that are inserted and removed in a LIFO(Last In First Out) fashion. So, when we need a plate, we take (pop) from the top of the stack, and when we want to add a plate, we put (push) it at the top as well. We cannot add or remove a plate at the middle of the stack.

We can perform various operations on stack other than push() and pop(). We can see the topmost element in the stack using peek(); we can know the size of the stack using the size() method. Also we can check if the stack is empty using the empty() method.

The Java collections framework has a Stack Class that provides the functionality of the Stack Data structure. The Stack class extends the Vector class.

LIFO or FILO? :)

00:05 - info
00:16 - Initialize the stack
00:37 - .empty()
00:53 - .push(e)
01:25 - .size()
01:39 - .peek()
02:00 - .pop()

#howto #java #easyway #firststep #stack #lifo #filo

Music track: Too Hot by Aylex
Source: https://freetouse.com/music
Free Background Music for Video


On this page of the site you can watch the video online Java: Stack (LIFO: Last In First Out) with a duration of hours minute second in good quality, which was uploaded by the user HowTo: 13 January 2024, share the link with friends and acquaintances, this video has already been watched 815 times on youtube and it was liked by 3 viewers. Enjoy your viewing!