@Test public void test() { int[] array = {9,0,1, 2, 5, 8, 1, 5, 1, 4, 6, 5, 4, 5, 4, 1, 5, 10}; System.out.println(Arrays.toString(countSort(array))); } static int[] countSort(int[] array) { //1.得到数列的最大值 int max = array[0]; int min = array[0]; for (int i = 1; i < array.length; i++) { if(array[i]>max){ max=array[i]; } } //2.根据数列最大值确定统计数组的长度 int[] countArray=new int[max+1]; for (int i = 0; i < array.length; i++) { countArray[array[i]]++; } int index=0; int[] sortArray=new int[array.length]; for (int i = 0; i < countArray.length; i++) { for (int j = 0; j < countArray[i]; j++) { sortArray[index++]=i; } } return sortArray; }