MCPcopy Index your code
hub / github.com/BruceEckel/OnJava8-Examples / main

Method main

collections/PriorityQueueDemo.java:8–42  ·  view source on GitHub ↗
(String[] args)

Source from the content-addressed store, hash-verified

6
7public class PriorityQueueDemo {
8 public static void main(String[] args) {
9 PriorityQueue<Integer> priorityQueue =
10 new PriorityQueue<>();
11 Random rand = new Random(47);
12 for(int i = 0; i < 10; i++)
13 priorityQueue.offer(rand.nextInt(i + 10));
14 QueueDemo.printQ(priorityQueue);
15
16 List<Integer> ints = Arrays.asList(25, 22, 20,
17 18, 14, 9, 3, 1, 1, 2, 3, 9, 14, 18, 21, 23, 25);
18 priorityQueue = new PriorityQueue<>(ints);
19 QueueDemo.printQ(priorityQueue);
20 priorityQueue = new PriorityQueue<>(
21 ints.size(), Collections.reverseOrder());
22 priorityQueue.addAll(ints);
23 QueueDemo.printQ(priorityQueue);
24
25 String fact = "EDUCATION SHOULD ESCHEW OBFUSCATION";
26 List<String> strings =
27 Arrays.asList(fact.split(""));
28 PriorityQueue<String> stringPQ =
29 new PriorityQueue<>(strings);
30 QueueDemo.printQ(stringPQ);
31 stringPQ = new PriorityQueue<>(
32 strings.size(), Collections.reverseOrder());
33 stringPQ.addAll(strings);
34 QueueDemo.printQ(stringPQ);
35
36 Set<Character> charSet = new HashSet<>();
37 for(char c : fact.toCharArray())
38 charSet.add(c); // Autoboxing
39 PriorityQueue<Character> characterPQ =
40 new PriorityQueue<>(charSet);
41 QueueDemo.printQ(characterPQ);
42 }
43}
44/* Output:
450 1 1 1 1 1 3 5 8 14

Callers

nothing calls this directly

Calls 5

printQMethod · 0.95
addAllMethod · 0.80
splitMethod · 0.80
sizeMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected