Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt in Using the PriorityQueue Class

 
archu sweet
Ranch Hand
Posts: 66
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


In the declaration " PriorityQueue<Integer> pq2 =
new PriorityQueue<Integer>(10,pqs) "

i'm unable to understand as why 10 is added ???javascript:emoticon('');

This code was taken from kathy sierra 1.5 scjp....
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you check the Javadocs for PriorityQueue? They explain what the constructor arguments mean.
 
archu sweet
Ranch Hand
Posts: 66
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ya i have checked....Help me out please...javascript:emoticon('');
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Javadocs tell you that the 10 sets the initial capacity of the queue. They also say
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.

When you add items that take the queue beyond the capacity, it has to increase the size of the internal array. This takes a bit of time. So if you know how big the queue has to get you can set the capacity to be big enough in the first place, which saves this time.
 
archu sweet
Ranch Hand
Posts: 66
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@ Matthew Brown :


Thanks a ton!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic