mehmet said:
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.