萌新求问

T E T E 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
public class Test { public static void main(String[] args) { ArrayList<Integer> list = new ArrayList<>(); list.add(3); list.add(1); list.add(2); list.add(5); list.add(4); Collections.sort(list, new Comparator<Integer>() { @Override public int compare(Integer o1, Integer o2) { System.out.println(o1); System.out.println(o2); System.out.println("-----------"); return o2 - o1; } }); System.out.println(list); } } (----------------------------------------------) 1 3 ----------- 2 1 ----------- 2 1 ----------- 2 3 ----------- 5 2 ----------- 5 3 ----------- 4 2 ----------- 4 3 ----------- 4 5 ----------- [5, 4, 3, 2, 1] 为什么2和1会比较两次,还有5和4不跟1比较
...全文

相关推荐

评论 5
收藏 已收藏
分享
返回顶部
T E
Java SE 62,621 成员 307,251 内容