From the course: Nail Your Java Interview

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Using queues in technical interviews

Using queues in technical interviews - Java Tutorial

From the course: Nail Your Java Interview

Start my 1-month free trial

Using queues in technical interviews

- [Instructor] A queue represents an ordered list of objects, just like a list, but its intended use is slightly different. A queue is designed to have elements inserted at the end of the queue, and elements are removed from the beginning of the queue. If you think of a line at a supermarket, the first person in line is always the first person out of line. The last person that joins the line is also the last person out of line. To use queues in Java, we have the java.util.Queue interface. Since an interface is not concrete, we'll need to instantiate an implementation of the interface in order to use it. In Java, we can choose between a linked list and a priority queue. A linked list is a pretty standard queue implementation, so we're going to use this implementation in our example. Let's take a look at how this works in code. Here, we have an example where we want to process the requests of a series of people in line in…

Contents