On the collections framework Java provides the Queue , that can be mimicked by a List also. What would be a unique use of Queue that cannot be done by other collections framework ?
In fact the code snippets used by docs.oracle.com also point out that this is not a implementation that would necessarily require a Queue. What would be a real-time implementation of a Queue that can explain its applicability clearly ?.
https://docs.oracle.com/javase/tutorial/collections/interfaces/queue.html
[In the following example program, a queue is used to implement a countdown timer. The queue is preloaded with all the integer values from a number specified on the command line to zero, in descending order. Then, the values are removed from the queue and printed at one-second intervals. The program is artificial in that it would be more natural to do the same thing without using a queue, but it illustrates the use of a queue to store elements prior to subsequent processing.]
import java.util.*;
public class Countdown {
public static void main(String[] args) throws InterruptedException {
int time = Integer.parseInt(args[0]);
Queue<Integer> queue = new LinkedList<Integer>();
for (int i = time; i >= 0; i--)
queue.add(i);
while (!queue.isEmpty()) {
System.out.println(queue.remove());
Thread.sleep(1000);
}
}
}