1:01 pm - Wednesday February 22, 2017

PriorityQueue example program for retrieving, but does not remove, the head of this queue, or returns null if this queue is empty using Peek() 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   for  retrieving, but does not remove, the head of this queue, or returns null if this queue is empty using  Peek() method.

Example Program


import java.util.PriorityQueue;
import java.util.comparator;

public class PriorityQ {
	public static void main(String[] args) {

		PriorityQueue<Integer> PQ = new PriorityQueue<Integer>();
		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);
		}
		System.out.println("The head of this list is: " + PQ.peek());
	}

}



Output

The default way:

     12

     89

     56

     100

     103

   The head of this list is: 12

Specified by:

peek in interface Queue<E>

Returns:

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

BACK

Filed in: Z-A All Java Codes

Comments are closed.