Does anyone have a useful mnemonic for implementing Comparator?
comparator.compare(a, b) < 0
<==> a < b
I use this simple "substraction" mnemonic:
first - second
So, if first
is "less" than second
you'll get negative result, otherwise - positive or zero if they are equal.
I am not sure what you mean by mnemonic. However, I have had a very similar cognitive dissonance.
I am very visual, so I use the number line (the one I was taught in grade school). I just visualize the negative numbers as "left", 0 as "center" and positive numbers as "right". That the corresponds to the truth: -1 < 0 < 1