The question is already answered. I am just trying to add a simpler demonstration.
While using Comparator#compare, two integers are compared as following by the result of compare function.
* Result is negative -> first element is smaller
* Result is 0 -> they are same
* Result is positive -> first element is greater
When you use n1 - n2
:
* Result is negative -> n1 is smaller
* Result is 0 -> n1 and n2 are same
* Result is positive -> n1 is greater
When you use n2 - n1
:
* Result is negative -> n2 is smaller
* Result is 0 -> n1 and n2 are same
* Result is positive -> n2 is greater
Edit
Following table is just to demonstrate that subtraction can be used for compare operations. If the operands and result does not fit into the datatype any operation will produce wrong result.

Integer.MIN_VALUE
, the code is going to break. Replace that broken lambda with a real comparison function. - Jim Mischel