queue initiate

Discussion in 'Java' started by mehmet canayaz, Sep 19, 2005.

  1. can anyone initiate a queue with the new index ??
    I am trying stuff like:

    //queue with max 20 int elements
    Queue<int> myQ = new Queue<int> (20);

    mican
     
    mehmet canayaz, Sep 19, 2005
    #1
    1. Advertising

  2. mehmet canayaz wrote:
    > can anyone initiate a queue with the new index ??


    This would normally be the sort of thing to consult the API docs about.
    Nevertheless ...

    > I am trying stuff like:
    >
    > //queue with max 20 int elements
    > Queue<int> myQ = new Queue<int> (20);


    Are you talking about java.util.Queue? That's an interface, so you
    can't instantiate it directly. You must choose a particular
    implementation to instantiate, and the answer to your question then
    depends on which implementation is used. According to the API docs,
    "known" implementations of Queue are AbstractQueue, ArrayBlockingQueue,
    ConcurrentLinkedQueue, DelayQueue, LinkedBlockingQueue, LinkedList,
    PriorityBlockingQueue, PriorityQueue, and SynchronousQueue. Some of
    those are abstract classes, which you also cannot instantiate directly.

    Furthermore, type parameters must be reference types, not primitive
    types (such as int).

    You might want something like this:

    import java.util.Queue;
    import java.util.concurrent.ArrayBlockingQueue;

    ....

    Queue<Integer> myQueue = new ArrayBlockingQueue(20);

    You should, however, understand all the implications of choosing that
    particular Queue implementation. The API docs should help you there.

    --
    John Bollinger
     
    John C. Bollinger, Sep 19, 2005
    #2
    1. Advertising

  3. mehmet canayaz

    Roedy Green Guest

    On 18 Sep 2005 17:50:17 -0700, "mehmet canayaz" <>
    wrote or quoted :

    >can anyone initiate a queue with the new index ??
    >I am trying stuff like:
    >
    >//queue with max 20 int elements
    >Queue<int> myQ = new Queue<int> (20);


    Queue is an interface, not a class. You can thus have a Queue
    reference but you cannot directly instantiate a Queue.

    look up Queue in the Sun docs to see the many concrete classes that
    implement it. Let's presume you decided on an ArrayBlockingQueue<E>.

    Then you could say

    Queue<int> myQ = new ArrayBlockingQueue<int>(20);


    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Again taking new Java programming contracts.
     
    Roedy Green, Sep 19, 2005
    #3
  4. mehmet canayaz

    Roedy Green Guest

    On 18 Sep 2005 17:50:17 -0700, "mehmet canayaz" <>
    wrote or quoted :

    >can anyone initiate a queue with the new index ??
    >I am trying stuff like:
    >
    >//queue with max 20 int elements
    >Queue<int> myQ = new Queue<int> (20);


    see http://mindprod.com/jgloss/queue.html
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Again taking new Java programming contracts.
     
    Roedy Green, Sep 19, 2005
    #4
  5. mehmet canayaz

    Roedy Green Guest

    On Mon, 19 Sep 2005 04:07:51 GMT, Roedy Green
    <> wrote or quoted :

    >Queue<int> myQ = new ArrayBlockingQueue<int>(20);


    actually I have not tried that to see how far unboxing goes. You
    would normally write that

    Queue<Integer> myQ = new ArrayBlockingQueue<Integer>(20);
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Again taking new Java programming contracts.
     
    Roedy Green, Sep 19, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Paul L. Du Bois

    Queue.Queue-like class without the busy-wait

    Paul L. Du Bois, Mar 24, 2005, in forum: Python
    Replies:
    29
    Views:
    1,099
    Antoon Pardon
    Apr 4, 2005
  2. Russell Warren

    Is Queue.Queue.queue.clear() thread-safe?

    Russell Warren, Jun 22, 2006, in forum: Python
    Replies:
    4
    Views:
    712
    Russell Warren
    Jun 27, 2006
  3. Kceiw
    Replies:
    3
    Views:
    1,034
    Jim Langston
    Mar 14, 2006
  4. Gabriel Rossetti
    Replies:
    3
    Views:
    584
    Jerry Hill
    Apr 25, 2008
  5. Kris
    Replies:
    0
    Views:
    517
Loading...

Share This Page