Java doc:
An unbounded priority queue based on a priority heap.
The elements of the priority queue are ordered according to their natural ordering, or by a Comparator provided at queue construction time, depending on which constructor is used.
A priority queue does not permit null elements.
A priority queue relying on natural ordering also does not permit insertion of
non-comparable objects (doing so may result in ClassCastException).
Also says:
The head of this queue is the least element with respect to the specified ordering. If multiple elements are tied for least value, the head is one of those elements -- ties are broken arbitrarily. The queue retrieval operations poll, remove, peek, and element access the element at the head of the queue.
What you are outputting is the toString()
method. And the output is due how that method iterates the tree. The same order as the Iterator
.