12:23 am - Thursday March 23, 2017

PriorityQueue program using poll() method

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

BACK

This Program is used PriorityQueue using poll() method.

Example Program


import java.util.PriorityQueue;

public class PriorityQ {

public static void main(String[] args) {

PriorityQueue PQ = new PriorityQueue ();

PQ.add(100);

PQ.add(12);

PQ.add(56);

PQ.add(89);

PQ.add(103);

System.out.println("The default way:");

for(Integer number: PQ){

System.out.println(number);

}

PQ.poll();

System.out.println("The polled way:");

for(Integer number : PQ){

System.out.println(number);

}

}

}

 

Output

The default way:

12

89

56

100

103

The polled way:

89

56

100

103

 

Description copied from interface: Queue

Retrieves and removes the head of this queue, or returns null if this queue is empty.

Specified by:

poll in interface Queue<E>

Returns:

the head of this queue, or null if this queue is empty.

BACK

Filed in: Java Examples, Z-A All Java Codes

Comments are closed.