Java queues don't have enqueue and dequeue methods, these operations are done using the following methods:

Enqueuing:

  • add(e): throws exception if it fails to insert the object
  • offer(e): returns false if it fails to insert the object

Dequeuing:

  • remove(): throws exception if the queue is empty
  • poll(): returns null if the queue is empty

Take a look to the first object in the queue:

  • element(): throws exception if the queue is empty
  • peek(): returns null if the queue is empty

The add method, which Queue inherits from Collection, inserts an element unless it would violate the queue's capacity restrictions, in which case it throws IllegalStateException. The offer method, which is intended solely for use on bounded queues, differs from add only in that it indicates failure to insert an element by returning false.

(see: http://docs.oracle.com/javase/tutorial/collections/interfaces/queue.html)

You can also check this as this is more useful:

http://docs.oracle.com/cd/B10500_01/appdev.920/a96587/apexampl.htm

Answer from Manish Doshi on Stack Overflow
๐ŸŒ
Delft Stack
delftstack.com โ€บ home โ€บ howto โ€บ java โ€บ enqueue and dequeue java
Enqueue and Dequeue in Java | Delft Stack
February 15, 2024 - As you can see, addition (enqueue) in the queue will always be from the back, and removal (dequeue) will always be from the front. Now that you have a concrete understanding of the queue letโ€™s take a look at the implementation of the queue in Java.
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 70387265 โ€บ manual-enqueue-and-dequeue-in-java
data structures - Manual enqueue and dequeue in Java - Stack Overflow
In dequeue, you just need to increment front and decrement size. private final int[] data = new int[10]; private int size, front, rear; public int enqueue(int n) { if (size == data.length) { throw new RuntimeException("Queue is full."); } data[rear] = n; rear = (rear + 1) % data.length; size++; return n; } public int dequeue() { if (size == 0) { throw new RuntimeException("Queue is empty."); } int e = data[front]; front = (front + 1) % data.length; size--; return e; }
๐ŸŒ
LMU
cs.lmu.edu โ€บ ~ray โ€บ notes โ€บ queues
queues
*/ public interface Queue { /** * Adds the given item to the rear of the queue. */ void enqueue(Object item); /** * Removes the front item from the queue and returns it. * * @exception java.util.NoSuchElementException if the queue is empty. */ Object dequeue(); /** * Returns the front item from the queue without popping it.
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ queue-data-structure-definition-and-java-example-code
Queue Data Structure โ€“ Definition and Java Example Code
March 4, 2022 - Enqueue: Adds an item from the back of the queue. Dequeue: Removes an item from the front of the queue.
๐ŸŒ
Programiz
programiz.com โ€บ dsa โ€บ queue
Queue Data Structure and Implementation in Java, Python and C/C++
*/ else { front++; } System.out.println("Deleted -> " + element); return (element); } } void display() { /* Function to display elements of Queue */ int i; if (isEmpty()) { System.out.println("Empty Queue"); } else { System.out.println("\nFront index-> " + front); System.out.println("Items -> "); for (i = front; i <= rear; i++) System.out.print(items[i] + " "); System.out.println("\nRear index-> " + rear); } } public static void main(String[] args) { Queue q = new Queue(); // deQueue is not possible on empty queue q.deQueue(); // enQueue 5 elements q.enQueue(1); q.enQueue(2); q.enQueue(3); q.enQueue(4); q.enQueue(5); // 6th element can't be added to because the queue is full q.enQueue(6); q.display(); // deQueue removes element entered first i.e.
๐ŸŒ
Educative
educative.io โ€บ answers โ€บ queue-vs-deque-in-java
Queue vs. deque in Java
enqueue(element): Inserts an item at the rear of the queue. dequeue(): Removes and returns the first item from the queue. peek(): Returns the first item without removing it. Usage: Queues are commonly used in scenarios like task scheduling, ...
Find elsewhere
๐ŸŒ
Software Testing Help
softwaretestinghelp.com โ€บ home โ€บ java โ€บ java queue โ€“ queue methods, queue implementation with examples
Java Queue - Queue Methods, Queue Implementation & Example
April 1, 2025 - #1) Enqueue: An operation to insert an element in the queue is Enqueue (function queueEnqueue in the program). For inserting an element at the rear end, we need to first check if the queue is full.
๐ŸŒ
CalliCoder
callicoder.com โ€บ java-queue
Java Queue Interface Tutorial with Examples | CalliCoder
February 18, 2022 - The process of adding an element at the back of the Queue is called Enqueue, and the process of removing an element from the front of the Queue is called Dequeue. Java provides a Queue interface which is part of Javaโ€™s collections framework.
๐ŸŒ
Techie Delight
techiedelight.com โ€บ home โ€บ queue โ€บ queue implementation in java
Queue Implementation in Java | Techie Delight
September 18, 2025 - That means the object inserted first will be the first one out, followed by the object inserted next. ... Enqueue: Inserts an item at the rear of the queue. Dequeue: Removes the object from the front of the queue and returns it, thereby decrementing ...
๐ŸŒ
Princeton CS
introcs.cs.princeton.edu โ€บ java โ€บ 43stack โ€บ Queue.java.html
Queue.java
November 27, 2022 - * * @param item the item to enqueue */ public void enqueue(Item item) { Node oldlast = last; last = new Node(); last.item = item; last.next = null; if (isEmpty()) first = last; else oldlast.next = last; n++; } /** * Removes and returns the item on this queue that was least recently added. * * @return the item on this queue that was least recently added * @throws NoSuchElementException if this queue is empty */ public Item dequeue() { if (isEmpty()) throw new NoSuchElementException("Queue underflow"); Item item = first.item; first = first.next; n--; if (isEmpty()) last = null; // to avoid loitering return item; } /** * Returns a string representation of this queue.
๐ŸŒ
Codecademy
codecademy.com โ€บ learn โ€บ linear-data-structures-java โ€บ modules โ€บ queues-java โ€บ cheatsheet
Linear Data Structures: Queues Cheatsheet | Codecademy
The .enqueue() method of the Java Queue class is used to add new data to the queue. It takes a single argument, data, which is added to the end of the queue using the LinkedList method .addToTail(). A print statement can be included to describe ...
๐ŸŒ
Quora
quora.com โ€บ What-does-enqueue-dequeue-do-For-example-if-my-list-is-6-7-4-and-I-have-to-enqueue-dequeue-what-would-the-list-look-like-after-teh-enqueue-dequeue-method
What does enqueue (dequeue()) do? For example if my list is (6, 7, 4) and I have to enqueue (dequeue()), what would the list look like after teh enqueue (dequeue()) method? - Quora
Answer (1 of 3): Enqueue and dequeue operations are for queue data structure which is FIFO (First In, First Out). So when enqueue operation is performed on queue, element has been queued at the end of queue and similarly, dequeue operation removes ...
๐ŸŒ
Princeton CS
introcs.cs.princeton.edu โ€บ java โ€บ code โ€บ javadoc โ€บ Queue.html
Queue
The Queue class represents a first-in-first-out (FIFO) queue of generic items. It supports the usual enqueue and dequeue operations, along with methods for peeking at the top item, testing if the queue is empty, getting the number of items in the queue, and iterating over the items in FIFO order.
๐ŸŒ
CodeSignal
codesignal.com โ€บ learn โ€บ courses โ€บ mastering-complex-data-structures-in-java โ€บ lessons โ€บ stacks-and-queues-in-java
Stacks and Queues in Java
Add (Enqueue): Adds an element to the end of the queue, following the First In, First Out (FIFO) order. Poll (Dequeue): Removes and returns the element at the front of the queue.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ queue-interface-java
Queue Interface In Java - GeeksforGeeks
Elements follow FIFO (First-In-First-Out) in LinkedList and priority order in PriorityQueue ยท Elements cannot be accessed directly using an index ... We cannot instantiate a Queue directly as it is an interface. Here, we can use a PriorityQueue class that implements this interface. ... import java.util.PriorityQueue; import java.util.Queue; public class Geeks{ public static void main(String[] args){ // Create a PriorityQueue of Integers Queue<Integer> pq = new PriorityQueue<>(); // Adding elements to the PriorityQueue pq.add(50); pq.add(20); pq.add(40); pq.add(10); pq.add(30); // Display the PriorityQueue elements System.out.println("PriorityQueue elements: " + pq); } }
Published ย  2 weeks ago
๐ŸŒ
CodeSignal
codesignal.com โ€บ learn โ€บ courses โ€บ advanced-built-in-data-structures-and-their-usage-1 โ€บ lessons โ€บ queues-and-deques-in-java
Queues and Deques in Java | CodeSignal Learn
A queue, similar to waiting in line at a store, operates on the "First In, First Out" or FIFO principle. Java's LinkedList class enables the implementation of queues. This class includes methods such as add() for adding items and poll() for removing items. The dequeued item, "Apple", was the ...
๐ŸŒ
Coderanch
coderanch.com โ€บ t โ€บ 770019 โ€บ java โ€บ Explain-Enqueue-Dequeue-Array
Explain Enqueue-Dequeue in Array (Beginning Java forum at Coderanch)
The enQueue() operation puts an element in the next empty slot at the back of the queue, and the deQueue() operation removes the element from the front of the queue simply by incrementing the index that keeps track of where the front of the queue starts. The reason that enQueue() takes a parameter ...
๐ŸŒ
Princeton University
algs4.cs.princeton.edu โ€บ 13stacks โ€บ Queue.java.html
Queue.java
February 8, 2023 - * * @param item the item to add */ public void enqueue(Item item) { Node<Item> oldlast = last; last = new Node<Item>(); last.item = item; last.next = null; if (isEmpty()) first = last; else oldlast.next = last; n++; } /** * Removes and returns the item on this queue that was least recently added. * * @return the item on this queue that was least recently added * @throws NoSuchElementException if this queue is empty */ public Item dequeue() { if (isEmpty()) throw new NoSuchElementException("Queue underflow"); Item item = first.item; first = first.next; n--; if (isEmpty()) last = null; // to avoid loitering return item; } /** * Returns a string representation of this queue.