Can I use Collections.binarySearch() method to search elements in a PriorityQueue? Otherwise, how can I apply search algorithms to a PriorityQueue?
I have this (class Evento implements Comparable):
public class PriorityQueueCAP extends PriorityQueue<Evento>{
// (...)
public void removeEventos(Evento evento){
Collections.binarySearch(this, evento); // ERROR!
}
}
And I got this error: “The method binarySearch(List>, T) in the type Collections is not applicable for the arguments (PriorityQueueCAP, Evento)”
Why?
Thanks in advance!
You should not apply a search algorithm to a priority queue. A priority queue is designed to provide efficient access to the highest priority element in the collection, and that is all.
I know that this is probably not the answer for which you were hoping; I’ve seen too many problems arise from using tools for unintended purposes, and felt I should offer a word of warning.