Does PriorityQueue heapify itself if any object in the collection is mutated so that it's key(used in comparator) changes?
问题 I just want to know if Java's PriorityQueue collection automatically heapifies, if any of the keys used in the comparator is mutated, or do i need to explicitly call heapify, to order the binary tree ? I am experimenting with the data structure to use it in a cache like setting, where an object in the collection should be immediately moved to the head, as soon as it is referenced. 回答1: The queue automatically heapifies on operations that mutates the queue itself, namely offer , poll , remove