Java - sort only subsection of array
问题 I have an array of characters String a = "badabcde"; char[] chArr = a.toCharArray(); // 'b','a','d','a','b','c','d','e' What's the easiest way to sort only a section of the array, given a start and end index? // 'b','a','d','a','b','c','d','e' subSort(array, startIndex, endIndex); Ex: subSort(chArr, 2, 5); // 'b','a','a','b','c','d','d','e' // sorts indices 2 to 5 回答1: I think public static void sort(char[] a, int fromIndex, int toIndex) answers your question. String a = "badabcde"; char[]