Java provides a Stack class for the familiar last-in, first-out data structure.You can think of a stack literally as a vertical stack of objects; when you add a new element, it gets stacked on top of the others.
- [Instructor] Another data structure in Java is stacks.…Java provides a stacks class…for the familiar last in, first out data structure or LIFO.…You can think of a stack literally…as a vertical stack of objects.…When you add a new element,…it gets stacked on top of the others.…When you pull an element off the stack,…it comes off the top.…In other words, the last element you added to the stack…is the first one to come back off.…
A stack is a linear list in which items are added at one end…and deleted from the same end.…Think of a stack of plates.…You can add clean plates to the top of the stack,…but when getting ready for a meal,…you take the top plates off first.…When using a stack,…when an item is added, you use the term push…or the push method.…When we want to remove an item from the stack, we use pop.…
Before using pop though,…it's important to test for an empty stack.…There is also a peek method…which is similar to the hasNext method…that can be used when reading data from the console…or a file.…It allows the programmer to look at the next value…
In this course, explore data structures in the Java language. Follow Peggy Fisher as she introduces you to several types of commonly-used data structures in Java. Peggy explores ArrayLists and LinkedLists, both of which implement the List interface, which extends the Collection interface and allows you to access list elements in a specific order. She also goes into the Vector, Stack, and Queue collection classes. To help you better understand these new concepts, Peggy wraps up the course with a challenge—creating a grocery list—and provides a solution for that challenge.
- Reviewing the types of data structures
- Working with the Collection interface and Iterable interface
- Working with ArrayLists and LinkedLists
- Using the Vector, Stack, and Queue collection classes