Jason S
Jason S

Reputation: 189856

java.util.Stack appropriate data structure?

Hmm. I'm noticing Stack is a subclass of Vector, and I thought Vector and Hashtable were considered "old" datastructures because of their builtin synchronization even if you don't need it. (vs. List, Map, etc. which don't provide it for you)

That and it's a class, not an interface.

Is there a more modern, recommended alternative?

Upvotes: 8

Views: 4700

Answers (2)

Jason S
Jason S

Reputation: 189856

I ended up using LinkedList for my purposes (add() and removeLast() being push and pop operations). Oops, looks like this is a duplicate Q.

Upvotes: 2

John Kugelman
John Kugelman

Reputation: 362037

java.util.Deque

Deques can also be used as LIFO (Last-In-First-Out) stacks. This interface should be used in preference to the legacy Stack class. When a deque is used as a stack, elements are pushed and popped from the beginning of the deque.

Upvotes: 15

Related Questions