Does a PriorityQueue allow elements already within the queue to be reordered?

后端 未结 3 1979
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-25 19:42

I want to augment or lower the priority of items in a PriorityQueue: for example, I might be downloading a long list of images and suddenly want the thirtieth one t

3条回答
  •  耶瑟儿~
    2021-01-25 19:57

    None of the collections in Java automatically reorders elements if you change the property that determine their order. For collections that depend on the .hashCode() , .equals() or some comparator, you are not allowed to change the object while it resides in the collection so that the hashcode/equals or comparator would yield different values.

    You have to remove, change, re-insert the object if you want to change its priority within a PriorityQueue.

提交回复
热议问题