请参阅开放的jdk源代码。我想这会有所帮助。
java.util.Collections:
132 public static <T extends Comparable<? super T>> void More ...sort(List<T> list) {133 Object[] a = list.toArray();134 Arrays.sort(a);135 ListIterator<T> i = list.listIterator();136 for (int j=0; j<a.length; j++) {137 i.next();138 i.set((T)a[j]);139 }140 }集合排序调用Arrays.sort
java.util.Arrays:
1218 public static <T> void More ...sort(T[] a, Comparator<? super T> c) {1219 T[] aux = (T[])a.clone();1220 if (c==null)1221 mergeSort(aux, a, 0, a.length, 0);1222 else1223 mergeSort(aux, a, 0, a.length, 0, c);1224 }Arrays.sort调用Arrays.mergeSort,您的答案在第1157行。
11451146 private static void More ...mergeSort(Object[] src,1147 Object[] dest,1148 int low,1149 int high,1150 int off) {1151 int length = high - low;11521153 // Insertion sort on smallest arrays1154 if (length < INSERTIONSORT_THRESHOLD) {1155 for (int i=low; i<high; i++)1156 for (int j=i; j>low &&1157 ((Comparable) dest[j-1]).compareTo(dest[j])>0; j--)1158 swap(dest, j, j-1);1159 return;1160 }11611162 // Recursively sort halves of dest into src1163 int destLow = low;1164 int destHigh = high;1165 low += off;1166 high += off;1167 int mid = (low + high) >>> 1;1168 mergeSort(dest, src, low, mid, -off);1169 mergeSort(dest, src, mid, high, -off);11701171 // If list is already sorted, just copy from src to dest. This is an1172 // optimization that results in faster sorts for nearly ordered lists.1173 if (((Comparable)src[mid-1]).compareTo(src[mid]) <= 0) {1174 System.arraycopy(src, low, dest, destLow, length);1175 return;1176 }11771178 // Merge sorted halves (now in src) into dest1179 for(int i = destLow, p = low, q = mid; i < destHigh; i++) {1180 if (q >= high || p < mid && ((Comparable)src[p]).compareTo(src[q])<=0)1181 dest[i] = src[p++];1182 else1183 dest[i] = src[q++];1184 }1185 }


