Duration: 16:28 minutes
Summary: In this video, we continue our discussion on generics and collections by talking about Priority Queue. When we think about queues, we think about a line of customers waiting in a line - the customer that comes first is helped first (FIFO queue, First In First Out). We start by creating a PriorityQueue in Integers. Be default the queue will sort those in terms of priority from smallest to largest. We use the offer() methods to add elements into the queue. We use peek() and poll() to get and remove the elements from the queue. Then, we create a PriorityQueue of Employees. We saw how we get an error message during runtime when the queue tries to process the Employee elements. The way we solve that is by implementing the Comparable interface. Now the queue knows how to sort the priorities of employees and process them.