java - Parameters in a Priority Queue Constructor -


lately have started work priority queues in java , found myself don't seem understand. have used comparator class sort priority queue in way.

here simple program did:-

package main;  import java.util.comparator; import java.util.priorityqueue;  class pq implements comparator<integer> {    public int compare(integer o1, integer o2) { // sort in descending order     return o2 - o1;    } }  public class main {    public static void main(string[] args) {     int[] list = { 1, 5, 6, 9, 10, 3, 5, 2, 13, 15, 17, 19, 25, 1, 0 };     pq pqs = new pq();      priorityqueue<integer> pq1 = new priorityqueue<integer>(10, pqs);     // "10" parameter does?      (int x : list) {       pq1.offer(x); // put values in queue     }      (int x : list) {       system.out.println(pq1.poll()); // pops out queue.     }   } } 

my problem integer parameter "10" means in priority queue constructor?(am passing don't know does)

i searched internet , found out used specify initial capacity , still unable understand clearly.

can explain me ?

thank time.

it initial capacity of 'priorityqueue'. when have doubts should refer official documentation of class.

it used in cases know in advance how space need (at least @ beginning) instantiated object can allocate enough memory store number of elements without having waste time allocating smaller amount of memory (to save space) , spending time alloc new memory needed.


Comments