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.