课程: Learning Java Collections

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

Using an ArrayDeque as a stack

Using an ArrayDeque as a stack - Java教程

课程: Learning Java Collections

Using an ArrayDeque as a stack

- [Instructor] In Java, the ArrayDeck is the recommended implementation for when we need a stack, which is one of the most frequent ways that we'll work with the deck. Let's work through a few examples to see how a deck works as a stack. For these examples, let's imagine the Landon Hotel has an older voicemail system that uses a last in first out approach to store messages. So messages will be stored in reverse of the order that they're received. And we'll just say there's no random access. This is similar to how your smartphone stores voicemails. More recent messages appear at the top and older messages at the bottom, except with a smartphone, you can play them in any order. So let's go ahead and we'll build our stack to work with these messages. To do that, I'm going to create a new deck that has a generic type of string. I'll name it messageStack, and I'll use an ArrayDeck implementation. Okay, so now we have our…

内容