I have a simple question. I am implementing PriorityQueue
in my project. My question is can i set a fixed size for PriorityQueue
is Java ?
As the oracle documentation here states, http://docs.oracle.com/javase/7/docs/api/java/util/PriorityQueue.html:
A priority queue is unbounded, but has an internal capacity governing the size of an array used to store the elements on the queue. It is always at least as large as the queue size. As elements are added to a priority queue, its capacity grows automatically. The details of the growth policy are not specified.
A possible workaround may be that you can check the size before performing any operation:
if (q.size() <= QUEUE_LIMIT)
//your code
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With