I am trying to dequeue based off the integer value in my priority queue, rather than the name (String) value. For instance, [Sally, 4] should be pulled before [John, 1]. Because 4 is higher in priority than 1. However the way I have structured my Queue, it is polling by alphabet from the first variable (name). Any step in the right direction would be greatly appreciated, thank you.
package stackqueuewood;
import java.util.PriorityQueue;
import java.util.ArrayList;
public class StackQueueWood {
public static void main(String[] args) {
ArrayList<String> people = new ArrayList<>();
people.add(person("Tom", 3));
people.add(person("Dick", 4));
people.add(person("Harry", 2));
PriorityQueue<String> pQ = new PriorityQueue<>();
pQ.addAll(people);
System.out.println("The current queue size is: " + pQ.size());
System.out.println("The current queue is: \n" + pQ);
System.out.println(pQ.peek());
pQ.poll();
System.out.println(pQ);
}
public static String person(String name, int priority){
return ("(" + name + ", " + priority + ")");
}
}