This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Comparing in Java (with Comparable or Comparator) works as follows: - if the return value is negative, the first value is considered smaller than the second - if the return value is positive, the first value is considered larger than the second - if the return value is 0, the values are considered to be equal.
So let's apply this to your example. Let's take 5 and 6. Compare(5, 6) will return 1, so 5 will be larger than 6. As a result, 5 will be put closer to the end than 6.
There is another problem with your compare() method. It will work as long as the parameter values remain within a restricted range, but you need to consider what happens if the values -1234567890 and 1234567890 are compared. Try it and see!