Replace the old stack with what from the Java collections?

Perhaps this is a minor Java issue.

I have used Stack repeatedly .

I read that this is considered an inherited class, and due to the fact that subclasses Vectormake its performance poor in single-threaded applications.

My question is: what is the best alternative among Java Collection classes?

Is there another class Stack(by a different name) that is being selected?

I mean, to implement the arround stack, another existing data structure is simple, but I would expect an existing one to exist Stack.

+5
source share
6 answers

Javadoc (, 1,6 1,7), 1.4.2 , :

LIFO Deque ,

http://docs.oracle.com/javase/6/docs/api/java/util/Stack.html http://docs.oracle.com/javase/7/docs/api/java/util/Stack.html

+4

LinkedList push pop. . Deque.

Commons Collections ArrayStack.

+2
+2
source

You can use Deque to add and remove objects from one end.

+1
source

You can use LinkedListone that implements the interface Dequeand allows you to click and pop up.

+1
source

From Stack javadoc:

A more complete and consistent set of LIFO stack operations provided by the Deque interface and its implementations, which should be used for this class.

Deque stack = new ArrayDeque ();

0
source

All Articles