Queue is an interface in Java that follows the FIFO (First In, First Out) principle. This means that the element added first to the queue is the first one to be removed.
Elements can be added to a queue using the add() or offer() method. Since Queue is an interface, it cannot be instantiated directly. Instead, a concrete implementation such as LinkedList or ArrayDeque is used.
Example Code:
import java.util.Queue;
import java.util.LinkedList;
Queue<Integer> queue = new LinkedList<>(); // initialization of Queue
queue.add(1);
queue.add(2);
System.out.print(queue); // prints [1, 2]
sukanya meruva Answered question