我试图插入整数PriorityQueue,我知道:
如果在PriorityQueue构造a时未指定比较器,则使用存储在队列中的数据类型的默认比较器.默认比较器将按升序对队列进行排序
但是,我得到的输出不是按排序顺序.运行以下代码后的输出是:[2, 4, 8, 6]
public static void main(String args[]) {
PriorityQueue<Integer> q = new PriorityQueue<Integer>(10);
q.offer(4);
q.offer(2);
q.offer(8);
q.offer(6);
System.out.print(q);
}
Run Code Online (Sandbox Code Playgroud)
有人可以解释一下原因吗?