title: Making a Java PriorityQueue into a stable priority queue
body: <p>I'm trying to implement a stable (first in first out) priority queue in Java.  Supposing that the key is a name and the value is an age, I know I can make an unstable priority queue like this:</p>
  
  <pre><code>Queue&lt;Map.Entry&lt;String, Integer&gt;&gt; pq = new PriorityQueue&lt;Map.Entry&lt;String, Integer&gt;&gt;(100, ageComparator);
  </code></pre>
  
  <p>This does pretty much everything that I need it to, except that it doesn't maintain order of key-value pairs as I insert them (or remove them).</p>
  
  <p>I've found a "work around" by making a LinkedList, which offers essentially all of the same functionality, except that it doesn't include a constructor with a comparator option, and I feel that it must be slower since I maintain value ordering by calling <code>Collections.sort()</code> after each queue operation.</p>
  
  <p>So I guess that really there are two options that I'm interested in.  First, how could I edit the PriorityQueue above to maintain insertion and removal order?  Or second, how could I force my LinkedList option to use a comparator immediately rather than having to call a sort on each operation?  Thanks!</p>
  
  <p>EDIT:</p>
  
  <p>Thanks for the good question in the first comment that was posted.  By FIFO, I mean that for key-value pairs with equal values, the pair which is put in first should be extracted first.</p>