The java.util.Queue Interface in Java


Queues support First-In-First-Out (FIFO) data processing. Use implementations like LinkedList for general use or ArrayDeque for more efficient stack and queue operations.

Source Code

Queue queue = new LinkedList();
queue.offer(1); // Adds an element
queue.offer(2);
System.out.println(queue.poll()); // Removes and returns the head, outputs 1
System.out.println(queue.peek()); // Returns the head without removing, outputs 2
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments