I'm trying to use a priorityqueue and I assume the elements are added in the "natural order"..
WHen I print the elements its not in sorted order..I would expect the result- 1,2,3,4
package scratch;
import java.util.*;
public class test {
public static void main(String[] args) {
PriorityQueue<String> pq = new PriorityQueue<String>();
pq.add("2");
pq.add("4");
System.out.println(pq.peek()+" ");
pq.offer("1");
pq.add("3");
System.out.println(pq);
/*System.out.println(pq.poll() + " ");
System.out.println(pq);*/
}
}
OUtput:
2 [1, 3, 2, 4]