Changing Java PriorityQueue to a Max PQ [duplicate]
This question already has an answer here: Change priorityQueue to max priorityqueue 14 answers The Priority Queue implementation in the Java standard library appears to be a min Priority Queue which I found somewhat confusing. In order to turn it into a max one I created a custom comparator object. Comparator<Integer> cmp = new Comparator<Integer>() { public int compare( Integer x, Integer y ) { return y - x; } }; I was wondering if there was a more elegant solution. Essentially I wan't a generic priority queue that could be used to implement Dijkstras etc. I didn't even realise there would be