Wrong order in java.util.PriorityQueue and specific Comparator
i am very confused with this little example of java.util.PriorityQueue and my own Comparator: In this code i get a wrong order in the queue. The result is: 5,8,7 instead of 5,7,8 Is there anything wrong with my Comparator<Vertex> ? Thank you for your help. public class Test { public static void main(String[] args) { PriorityQueue<Vertex> priorityQueue = new PriorityQueue<Vertex>(new Comparator() { @Override public int compare(Object o1, Object o2) { Vertex u = (Vertex) o1; Vertex v = (Vertex) o2; return Integer.compare(new Integer(u.distance), new Integer(v.distance)); } }); Vertex vertex1 =