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
🌐
GeeksforGeeks
geeksforgeeks.org › dsa › basic-operations-for-queue-in-data-structure
Basic Operations for Queue Data Structure - GeeksforGeeks
using System; using System.Collections.Generic; public class GfG { public static void Main() { Queue<int> q = new Queue<int>(); // inserting elements at rear q.Enqueue(1); q.Enqueue(8); q.Enqueue(3); // deleting element from front q.Dequeue(); } } ... // Driver Code let q = []; // inserting elements at rear q.push(1); q.push(8); q.push(3); // deleting element from front q.shift(); Time Complexity: O(1), since deleting from the front takes constant time. In JavaScript, there’s no built-in queue, so we use arrays.
Published   September 23, 2025
🌐
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.
🌐
W3Schools
w3schools.com › dsa › dsa_data_queues.php
W3Schools.com
This way of creating queues in Python is also more similar to how queues can be created in other programming languages like C and Java. ... class Queue: def __init__(self): self.queue = [] def enqueue(self, element): self.queue.append(element) def dequeue(self): if self.isEmpty(): return "Queue is empty" return self.queue.pop(0) def peek(self): if self.isEmpty(): return "Queue is empty" return self.queue[0] def isEmpty(self): return len(self.queue) == 0 def size(self): return len(self.queue) # Create a queue myQueue = Queue() myQueue.enqueue('A') myQueue.enqueue('B') myQueue.enqueue('C') print("Queue: ", myQueue.queue) print("Dequeue: ", myQueue.dequeue()) print("Peek: ", myQueue.peek()) print("isEmpty: ", myQueue.isEmpty()) print("Size: ", myQueue.size()) Try it Yourself »
🌐
HappyCoders.eu
happycoders.eu › algorithms › java-queue
Queue Interface in Java (+ Code Examples)
November 27, 2024 - The Queue interface defines six methods for inserting, removing, and viewing elements. For each of the three queue operations "Enqueue", "Dequeue", and "Peek", the interface defines two methods: one that throws an exception in case of an error and one that returns a special value (false or null).
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › util › Queue.html
Queue (Java Platform SE 8 )
3 days ago - Java™ Platform Standard Ed. 8 ... AbstractQueue, ArrayBlockingQueue, ArrayDeque, ConcurrentLinkedDeque, ConcurrentLinkedQueue, DelayQueue, LinkedBlockingDeque, LinkedBlockingQueue, LinkedList, LinkedTransferQueue, PriorityBlockingQueue, PriorityQueue, SynchronousQueue ... A collection designed for holding elements prior to processing. Besides basic Collection operations, queues provide additional insertion, extraction, and inspection operations.
🌐
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 ...
🌐
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
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-program-to-implement-the-queue-data-structure
Java Program to Implement the Queue Data Structure - GeeksforGeeks
May 27, 2024 - // Java Program to Implement // Queue Data Structure class Queue { private int[] arr; private int front; private int rear; private int capacity; private int size; // Constructor to initialize the queue public Queue(int capacity) { this.capacity = capacity; arr = new int[capacity]; front = 0; rear = -1; size = 0; } // Insert an element at the rear of the queue public void enqueue(int item) { if (isFull()) { System.out.println("Queue is full"); return; } rear = (rear + 1) % capacity; arr[rear] = item; size++; } // Remove and return the element from the front of the queue public int dequeue() { i
🌐
Simplilearn
simplilearn.com › home › resources › software development › circular queue in data structure: overview, linked list and more
Circular Queue in Data Structure: Overview, Implementation | Simplilearn
July 23, 2024 - Know what is circular queue in data structure and how to implement it using array and linked list to manage the execution of computing process. Read more.
Address   5851 Legacy Circle, 6th Floor, Plano, TX 75024 United States
🌐
Hackajob
hackajob.com › talent › blog › how-to-implement-stacks-and-queues-in-java
How to Implement Stacks and Queues in Java
August 6, 2025 - The enqueue function takes the element to be inserted and checks whether the queue is full, before inserting it to the rear. This is done by incrementing the rear pointer and appending it to that index.
🌐
GeeksforGeeks
geeksforgeeks.org › dsa › array-implementation-of-queue-simple
Queue using Array - Simple Implementation - GeeksforGeeks
September 20, 2025 - The front pointer tracks the first valid element. Enqueue: Insert at the next available position at the end. No rear pointer is required. Dequeue: Remove the element at front and increment the front pointer.
🌐
Javatpoint
javatpoint.com › java-deque-arraydeque
Deque & ArrayDeque
Java Deque and ArrayDeque with methods of Deque interface and ArrayDeque class, Deque implementation, Deque and ArrayDeque examples with real life scenarios, storing and fetching data etc.
🌐
Sbme-tutorials
sbme-tutorials.github.io › 2020 › data-structure-FALL › notes › week06b.html
Week 6-b: Queues
Many implementations (e.g arrays and linked lists) Queue behaviour == FIFO (first in, first out). enqueue: Adds element e to the back of queue. dequeue: Removes and returns the first element from the queue. first: Returns the first element of the queue, without removing it.
🌐
Medium
medium.com › codex › queue-data-structure-implementation-in-java-d53bb991a890
Queue Data Structure Implementation in Java | by shivam bhatele | CodeX | Medium
April 11, 2023 - The time complexity to perform this operation is O(1). Dequeue: Since the enqueue operation is used to insert elements in the queue so the dequeue operation is used to delete the elements from 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.
🌐
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; }
🌐
Medium
thegeekplanets.medium.com › stacks-and-queues-in-java-a-brief-overview-of-their-concepts-and-implementations-724ab7b031d0
Stacks and Queues in Java: A Brief Overview of Their Concepts and Implementations | by @thegeekplanets | Haridas Kanure | Medium
November 12, 2024 - class CircularQueue { private int[] data; private int front, rear, size; public CircularQueue(int capacity) { data = new int[capacity]; front = rear = size = 0; } public boolean enqueue(int value) { if (size == data.length) return false; // Queue is full data[rear] = value; rear = (rear + 1) % data.length; size++; return true; } public int dequeue() { if (size == 0) throw new NoSuchElementException("Queue is empty"); int result = data[front]; front = (front + 1) % data.length; size--; return result; } public int peek() { if (size == 0) throw new NoSuchElementException("Queue is empty"); return data[front]; } public boolean isEmpty() { return size == 0; } }