What is the Java C ++ STL Queue equivalent?

I was looking through Java docs to look for the Java equivalent for C ++ STL Queue, but all I found was an interface called Queueand a bunch of implementations, I can not make heads or tails.

Does Java have an implementation for Queue, which is just a FIFO data structure without added bells and whistles? I need only operations enqueue, dequeueand front, and the data structure should allow duplicates.

+5
source share
5 answers

Queuewill work. Use any implementation that you like. LinkedListor ConcurrentLinkedQueuefor example.

enqueue= offer(..)
dequeue= poll()
front=peek()

+7
source

This docs page lists all the classes that implement the interface. So, for example, you can do the following ( DISCLAIMER: was not near the compiler ):

Queue<E> q = new LinkedList<E>();

E x1 = new E();
E x2 = new E();
E x3;

q.offer(x1);
q.offer(x2);

x3 = q.poll();
+3
source

LinkedList. , , , .

+1

java.util.LinkedList, , , "", "" "".

+1

, , , , - . . Deque .

0

All Articles