Java PriorityQueue class
import java.util.PriorityQueue; public class Main { public static void main(String[] args) { // queue of capacity 11 PriorityQueue<Double> queue = new PriorityQueue<>(); // insert elements to queue queue.offer(1.2);/*from w w w. jav a 2s . com*/ queue.offer(2.8); queue.offer(3.4); System.out.print("Polling from queue: "); // display elements in queue while (queue.size() > 0) { System.out.printf("%.1f ", queue.peek()); // view top element queue.poll(); // remove top element } } }