I think they are very similar…And when do we need to use stack or queue, why not just use ArrayList or LinkedList to replace them?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Stack, is a Last-In-First-Out stack of objects derived fromVector, also a class.Vectorgoes with the “old” set of collections that Java originally shipped with, and derives ultimately fromAbstractCollection. Of note, there’s really one canonical implementation of aStack;Queues andLists have many well known implementations that can make a substantial performance difference when chosen correctly.Queueon the other hand follows theCollectioninterface from the “new” set of collections that are typically used today, so it follows the interfaces and comes with a variety of implementations.Stacks should be used when you need LIFO semantics, whileQueues should be used when you need First-In-First-Out semantics.ArrayListandLinkedListstore ordered collections of things, and don’t line up with the use-cases ofStackorQueuedirectly.Stacks andQueues are in a sense buffers of data, whereas the semantics of aListtypically make it such that it’s a store of data; nothing is stopping you from using aListto implement aStackor aQueue.