简体   繁体   English

在java中反向排序子数组

[英]Reverse Sorting a Subarray in java

My goal is to convert this Arrays.sort(nums, j+1, nums.length) into a reverse sort. 我的目标是将此Arrays.sort(nums, j+1, nums.length)转换为反向排序。 The only reverse sort information I can find doesn't seem to have the ability to sort a subarray. 我能找到的唯一反向排序信息似乎没有能力对子阵列进行排序。

And this gives me an error Arrays.sort(nums, j+1, nums.length, Collections.reverseOrder()); 这给了我一个错误Arrays.sort(nums, j+1, nums.length, Collections.reverseOrder());

由于Collections.reverseOrder()方法仅适用于引用类型,我的建议是你的“nums”应该保存引用类型,如Integer,Double ......或者如果你定义了自己的类,请确保你的类实现了Comparable接口

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM