What’s the sort order of Java’s Collections.sort(list, comparator)? small to big or big to small?

The sort order is always ascending, where the Comparator defines which items are larger than others.

From the documentation for Collections.sort(List<T> list,
Comparator<? super T> c):

Sorts the specified list according to the order induced by the specified comparator.

From the documentation for Comparator.compare(T,T):

Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)