Table of Contents

1. Queue Interface

The Queue interface is part of the Java Collections Framework and is used to hold multiple elements prior to processing. Queues typically, but not necessarily, order elements in a FIFO (First-In-First-Out) manner.

Common Implementations:

Key Methods:

Example Using Queue Interface:

import java.util.LinkedList;
import java.util.Queue;

public class QueueExample {
    public static void main(String[] args) {
        Queue<Integer> queue = new LinkedList<>();

        // Add elements to the queue
        queue.add(1);
        queue.add(2);
        queue.add(3);

        // Display elements
        System.out.println("Queue: " + queue);

        // Remove an element
        int removed = queue.remove();
        System.out.println("Removed element: " + removed);

        // Display the head element
        int head = queue.peek();
        System.out.println("Head of the queue: " + head);

        // Display elements after removal
        System.out.println("Queue after removal: " + queue);
    }
}


2. Set Interface