Sobes.tech
Junior — Middle

What is the data structure called that implements the FIFO principle?

sobes.tech AI

Answer from AI

A data structure that implements the FIFO (First In, First Out) principle is called a queue.

In Java, there is an interface Queue and its implementations, such as:

  • LinkedList (implements the Queue interface)
  • ArrayDeque
  • PriorityQueue (with priority, but also a queue)

Example of using a queue:

Queue<String> queue = new LinkedList<>();
queue.add("First");
queue.add("Second");

System.out.println(queue.poll()); // Outputs "First"
System.out.println(queue.poll()); // Outputs "Second"

Thus, a queue ensures the order of processing elements based on the FIFO principle.