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

前端 未结 4 1782

Apparently, it\'s not documented or I missed it.

Here\'s the link to the documentation and below\'s the text as an image:

EDIT(17/5): I think to

4条回答
  •  温柔的废话
    2021-02-01 02:34

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

    From the documentation for Collections.sort(List list, Comparator 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.

提交回复
热议问题