How to inspect a Queue, for the oldest element to the newest, without removing the items from the queue

The linked listed implements a deque, you can use a ListIterator to iterate in reverse

        final Deque<String> queue = new LinkedList<String>();
        queue.add("1");
        queue.add("2");
        queue.add("3");
        queue.add("4");

        final Iterator iter = queue.descendingIterator();

        // from this you can the iterate the queue
        while (iter.hasNext()) {

            System.out.println(iter.next());
        }
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License