2 Replies Latest reply on Nov 6, 2011 1:46 AM by EJP

    Behaviour of PriorityQueue using Java 6


      I have a below code to test PriorityQueue ordering of elements using it's natural order.

      Output of SOP1 is clear to me.

      I was expecting
      SOP2 as : [a, b, d]
      SOP3 as : [a, b, c, d]

      import java.util.*;
      class PQTest {
      public static void main(String... args) {
      PriorityQueue<String> pq = new PriorityQueue<String>();
           System.out.println(pq); //SOP1 output [b, d]
           System.out.println(pq); //SOP2 output [a, d, b]
           System.out.println(pq); //SOP3 output [a, c, b, d]

      Could somebody shed the light?
      Appreciate your help.