1. 使用`Arrays.sort()`方法:
import java.util.Arrays;int[] numbers = {5, 2, 8, 3, 1};Arrays.sort(numbers);
2. 冒泡排序:
public static void bubbleSort(int[] arr) {int n = arr.length;for (int i = 0; i < n - 1; i++) {for (int j = 0; j < n - i - 1; j++) {if (arr[j] > arr[j + 1]) {int temp = arr[j];arr[j] = arr[j + 1];arr[j + 1] = temp;}}}}

3. 选择排序:
public static void selectionSort(int[] arr) {int n = arr.length;for (int i = 0; i < n - 1; i++) {int minIndex = i;for (int j = i + 1; j < n; j++) {if (arr[j] < arr[minIndex]) {minIndex = j;}}if (minIndex != i) {int temp = arr[i];arr[i] = arr[minIndex];arr[minIndex] = temp;}}}
4. 快速排序:
public static void quickSort(int[] arr, int left, int right) {if (left < right) {int pivotIndex = partition(arr, left, right);quickSort(arr, left, pivotIndex - 1);quickSort(arr, pivotIndex + 1, right);}}private static int partition(int[] arr, int left, int right) {int pivot = arr[left];while (left < right) {while (left < right && arr[right] >= pivot) {right--;}if (left < right) {arr[left] = arr[right];left++;}while (left < right && arr[left] <= pivot) {left++;}if (left < right) {arr[right] = arr[left];right--;}}arr[left] = pivot;return left;}
以上是几种常见的排序方法,你可以根据具体需求选择合适的方法进行排序。
