数组排序java内置函数
时间: 2023-09-22 17:13:09 浏览: 104
在Java中,可以使用Arrays类的sort()方法来对数组进行排序。该方法位于java.util包中,因此在使用之前需要先导入这个包。该方法可以按照升序对数组进行排序,即从小到大。下面是使用Arrays.sort()方法对数组进行排序的示例代码:
import java.util.Arrays;
public class ArraySortExample {
public static void main(String[] args) {
int[] array = {5, 3, 9, 1, 7};
Arrays.sort(array);
System.out.println(Arrays.toString(array));
}
}
运行这段代码,输出结果将为:[1, 3, 5, 7, 9]。这就是通过Java内置的数组排序函数对数组进行排序的方法。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *3* [PHP数组排序函数](https://blog.csdn.net/weixin_39629679/article/details/115827682)[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^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *2* [java排序函数](https://blog.csdn.net/weixin_39551611/article/details/114560719)[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^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文