PriorityQueue implements Queue

PriorityQueue implements Queue:- In a priority queue, items are ordered by key value, so that the item with the lowest key (or in some implementations the highest key) is always at the front. Items are inserted in the proper position to maintain the order.

import java.util.PriorityQueue;

public class PriorityQueueExample {
    public static void main(String[] args) {
        PriorityQueue<string> priorityQueue = new PriorityQueue<string>();
        priorityQueue.add("test1");
        priorityQueue.add("test2");
        priorityQueue.add("test3");
        priorityQueue.add("test4");
        priorityQueue.add("test5");
        System.out.println(priorityQueue);
    }
}

output:
[test1, test2, test3, test4, test5]

People who read this post also read :



1 comments:

I would include examples of what you mean by order. Any List or a LinkedHashSet would show the same order, so you need to show how a PriorityQueue differs.

IMHO You should make sure you examples compile.

Post a Comment

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More