Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / September 2005

Tip: Looking for answers? Try searching our database.

queue initiate

Thread view: 
mehmet canayaz - 19 Sep 2005 01:50 GMT
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
John C. Bollinger - 19 Sep 2005 03:25 GMT
> 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.

Signature

John Bollinger
jobollin@indiana.edu

Roedy Green - 19 Sep 2005 05:07 GMT
>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);

Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.

Roedy Green - 19 Sep 2005 06:30 GMT
>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);
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.

Roedy Green - 19 Sep 2005 06:17 GMT
>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
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.