Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an unsynchronized java.util.Stack?

Is there an unsynchronized version of java.util.Stack?

ArrayList almost has everything I want, except there doesn't seem to be a method that removes last element in amortized constant time.

I want something that can act like a stack, but still let me have constant random access to the elements.

If there really isn't anything, it isn't a big deal for me to just roll out my own or just use java.util.Stack, but it seemed strange to me that I couldn't find Stack's non-synchronized counterpart, that I thought it might be worth asking (also Googling just seemed to point me to other implementations rather than a class in the standard library).

like image 958
math4tots Avatar asked Feb 16 '14 14:02

math4tots


1 Answers

When the Collections framework was expanded, Stack was replaced by the interface Deque. It supports the same push, pop, and peek methods of Stack.

Implementations of Deque include ArrayDeque and LinkedList.

like image 199
Boann Avatar answered Sep 22 '22 20:09

Boann