arrays的sort降序方法
时间: 2023-10-12 08:55:38 浏览: 106
要对数组进行降序排序,可以使用Arrays.sort()方法,并在数组后面加上Collections.reverseOrder()。具体的代码如下所示:
import java.util.Arrays;
import java.util.Collections;
public class Main {
public static void main(String\[\] args) {
Integer\[\] arr = {1, 4, 3, 8, 2, 9, 11, 3};
Arrays.sort(arr, Collections.reverseOrder());
System.out.println(Arrays.toString(arr));
}
}
这段代码会将数组arr按照降序进行排序,并输出排序后的结果。
#### 引用[.reference_title]
- *1* [Arrays.sort(int[] a)进行升序和降序](https://blog.csdn.net/m0_52261367/article/details/122830826)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* *3* [Java中的Arrays.sort(),升序降序?](https://blog.csdn.net/CQCQCQY/article/details/121677141)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文