10.7 Capacity of Priority Queue

#1

Why do we need to assign a capacity 16 to a priority queue, what if the elements number over 16? Does the capacity grow? I assume we need to keep all the elements in the stack, unlike in the previous problem, we use priority queue like a window. Thanks in advance.

0 Likes

#2

Hi @Hitchcock,

It is just initial capacity, and it will grow if the number of elements pass that. You can check https://docs.oracle.com/javase/7/docs/api/java/util/PriorityQueue.html#PriorityQueue(int) for more example.

0 Likes