java list sort多重排序,Java的Collections.sort(list,comparator)的排序顺序是什么?小到大还是大到小?...

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 too many confused this question to be a comparator question. It is not. The comparator compares between 2 elements. According to that comparison, the list sorted. How? Ascending or Descending?

I'll refine/simplify the question even further: If the comparator decides that element A is smaller than element B. In the sorted list, will element A be located at a smaller index than element B?

9BsSR.png

解决方案

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

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值