Swerrgy Smith wrote:Does anyone have a trick to remember this order?
It's very simple, and it's explained in the API documentation of java.util.Comparator.compare().
Suppose you want to order the numbers in ascending order. compare() should then return a negative number if i1 is less than i2, 0 if they are equal, and a positive number if i1 is greater than i2.
Now, think about what you get when you do i1 - i2 or i2 - i1 with respect to this. Just try it in your head with concrete numbers, for example i1 = 3 and i2 = 5. What happens? Does this match with what should happen?