3 ms·
I'll meet you halfway: ints.sort((o1, o2) -> { if (o1.equals(o2)) { return 0; } else if (o1 < o2) { return 1;
by twic 12y ago
I'll meet you halfway:
ints.sort((o1, o2) -> {
if (o1.equals(o2)) {
return 0;
} else if (o1 < o2) {
return 1;
} else {
return -1;
}
});
Or may i suggest a version with a guard clause and a simple ternary:
ints.sort((o1, o2) -> {
if (o1.equals(o2)) return 0;
return (o1 < o2) ? 1 : -1;
});
There's definitely no need for the 'new Comparator' boilerplate any more. That's not the kind of verbosity that adds clarity; it's just ceremony.
- deleted 12y ago[deleted]