Is there an unsynchronized java.util.Stack?

Is there an unsynchronized version java.util.Stack?

ArrayList has almost everything I want, except that there seems to be no method that removes the last element in an arithmetic constant time.

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

If there is really nothing, it’s just not easy for me to deploy my own or just use it java.util.Stack, but it seemed strange to me that I couldn’t find a Stacksynchronized analogue, that I thought it might be worth asking (also Google seemed to just point me to other implementations, not to a class in the standard library).

+4
source share
2 answers

When the collection structure was expanded, it Stackwas replaced by an interface Deque. It supports the same methods push, popand peek Stack.

Implementations Dequeinclude ArrayDequeand LinkedList.

+3
source

An alternative is offered in javadoc asDeque

Deque<Integer> stack = new ArrayDeque<Integer>();
+1
source

Source: https://habr.com/ru/post/1527191/


All Articles