javalistqueue

How to convert list to queue to achieve FIFO


Consider:

public List<Place> getAllInactivePlaces() {

    return this.placeDAO.findAllUnApprovedList();
}

The method I have shown above is to find all places. I need to convert Queue to get a FIFO (First in, first out).

Something like this:

Queue<Place>placeQueue = getAllInactivePlaces();

Solution

  • LinkedList

    If you currently have a list which is not a Queue such as ArrayList, pass your List to the constructor of an implementation of Queue like LinkedList. The LinkedList class implements Queue with FIFO behavior.

    Queue<Place> queue = new LinkedList<>(yourList);