• Post Reply Bookmark Topic Watch Topic
  • New Topic

advantage stack over linked list or queue  RSS feed

 
sam liya
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what are the advanetage of stack over link list or queue?
 
Muhammad Khojaye
Ranch Hand
Posts: 449
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If your requirement is that your collection must be thread safe then Vector or Stack would be reasonable choice because both list implementations have synchronized methods. Whereas ArrayList and LinkedList are not thread safe. The Stack class represents a last-in-first-out (LIFO) stack of objects, which can be filtered down based on this specific requirement. If your collection does not need to be thread safe then you can choose either ArrayList or LinkedList.
 
Campbell Ritchie
Marshal
Posts: 56598
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You appear to be asking several related questions. I suggest you read the Java™ Tutorials and the documentation about the individual classes, which you should find in the java.util package. A stack behaves completely differently from a List; as you have been told, "LIFO".
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
They are different models for storing data. They work differently, and each should be sued for the correct situation. In other words, you use a stack when you need stack behavior, you use a queue when you need queue behavior, and you use a linked list when you need linked list behavior.

It's kind of like saying "What's the advantage of a waiter over a cook or a busboy. There are times when you need each, and none can be used as a replacement for the others.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!