Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Using linked list as a queue

843789Sep 15 2009 — edited Sep 15 2009
I have a question about the collections group, in particular Queue.

If I have a statement like this:
Queue<E> queue = new LinkedList<E>();
Under which circumstances would it be beneficial to use it.
I used this in this code.
package generation;

import java.util.LinkedList;
import java.util.NoSuchElementException;
import java.util.Queue;

/**
 *
 * @author David
 */
public class EconomicLoadOrder<E>
{


    Queue<E> queue = new LinkedList<E>();

    public EconomicLoadOrder()
    {
        //Empty constructory
    }

    public void addGenerator(E gen)
    {
        this.queue.add(gen);
    }

    public E getNextGenerator() throws NoSuchElementException
    {
        return this.queue.remove();
    }
}
And I thought I would have been able to use the LinkedList method .pop(). in my getNextGenerator() method, but it seems I can only use the Queue method remove(). This is ok for what I want to do, but I just want to understand what is happening here and why this is so?
I don't intend on changing it, but is there a way of enableing my this.queue object calling poll() ?

regards
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 13 2009
Added on Sep 15 2009
7 comments
193 views