3:13 pm - Friday December 17, 3576

PriorityQueue example program to order the elements in this queue, or null if this queue is sorted according to the natural ordering of its elements use Comparator() 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 to order the elements in this queue or null if this queue is sorted according to the natural ordering of its elements  using Comparator() method.

Example Program


package com.example;

package com.example;

import java.util.Comparator;
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);
Comparator cmp = PQ.comparator();
System.out.println("Comparator value is: " + PQ);
}
}

 

Output

 Comparator value is: [12, 89, 56, 100, 103]

 

public Comparator<? super E> comparator()

Returns the comparator used to order the elements in this queue, or null if this queue is sorted according to the natural ordering of its elements.

Returns:

The comparator used to order this queue, or null if this queue is sorted according to the natural ordering of its elements.

BACK

 

 

Filed in: Java Examples

Comments are closed.