How do I use a PriorityQueue?
问题 How do I get a PriorityQueue to sort on what I want it to sort on? Also, is there a difference between the offer and add methods? 回答1: Use the constructor overload which takes a Comparator<? super E> comparator and pass in a comparator which compares in the appropriate way for your sort order. If you give an example of how you want to sort, we can provide some sample code to implement the comparator if you're not sure. (It's pretty straightforward though.) As has been said elsewhere: offer