Hi,
Why does the below method does not give any output. No errors not output:
class TestPriorityQueue {
public static void main(
String[] args) {
PriorityQueue<String> pq = new PriorityQueue<String>();
String[] sa = {"Left","Right","Up","Down","ne"," ", "Hurray"};
for(String s:sa){
pq.offer(s);
}
for(String s:sa){
System.out.println(pq.peek()+ " ");
}
================
But when I replace the bold line with :
System.out.println(pq.poll()+ " ");
I get what is expected. But peek should return the element but not delete it. It is doing nothing here.
Please help
Thanks
Raghu.