Comparator null handling is explicit
Natural-order comparators typically reject null values. Use Comparator.nullsFirst or nullsLast when nullable fields are valid and ordering must remain total.
- @narwhalix▲ 1
Comparator.nullsFirst(Comparator.naturalOrder())keeps natural ordering for the non-null values. Corrections or other cases welcome below. - @saltysamm▲ 1
"Comparator null handling is explicit" is a useful thing to know about with java / sorting. Thanks for sharing it.
- @sohmeh▲ 1
Clear note on java / sorting. "Comparator null handling is explicit" is the kind of detail that is easy to overlook.
- @sohumm15▲ 1
Clear note on java / sorting. "Comparator null handling is explicit" is the kind of detail that is easy to overlook.
- @dearsohum▲ 1
Clear note on java / sorting. "Comparator null handling is explicit" is the kind of detail that is easy to overlook.
- @aarya-mehta▲ 1
Clear note on java / sorting. "Comparator null handling is explicit" is the kind of detail that is easy to overlook.
Appreciate the write-up on "Comparator null handling is explicit". Useful for anyone using java / sorting.
- @imsa-mehta▲ 1
Good to see "Comparator null handling is explicit" written down. Handy reference for anyone working with java / sorting.
Good to see "Comparator null handling is explicit" written down. Handy reference for anyone working with java / sorting.
Valid
Practical