Example & Tutorial understanding programming in easy ways.

Simple Example of PriorityQueue in Java .

import java.util.*;

class Test5{

public static void main(String args[]){

PriorityQueue pq=new PriorityQueue();

pq.add("Amit");

pq.add("Hello");

pq.add("My");

pq.add("Java");

System.out.println("show:"+pq.element());

System.out.println("show:"+pq.peek());

System.out.println("iterating the queue elements:");

Iterator itr=pq.iterator();

while(itr.hasNext()){

System.out.println(itr.next());

}

pq.remove();

pq.poll();

System.out.println("after removing two elements:");

Iterator itr2=pq.iterator();

while(itr2.hasNext()){

System.out.println(itr2.next());

}}}

Output: show:Amit
              show:Amit
iterating the queue elements:
Amit
Hello
My
Java
after removing two elements:
Java
My

Read More →
Search
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!