### Question:
Arrays { public static <T> void sort(T[] array, int start, int end, Comparator<T> comparator) { checkBounds(array.length, start, end); sort(start, end, array, comparator); } private  Arrays(); static int binarySearch(T[] array, T object, Comparator<T> comparator); static int binarySearch(T[] array, int startIndex, int endIndex, T object, Comparator<T> comparator); static void fill(T[] array, T value); static void fill(T[] array, int start, int end, T value); static int hashCode(T[] array); static boolean equals(T[] array1, T[] array2); static void sort(T[] array, int start, int end, Comparator<T> comparator); static void sort(T[] array, Comparator<T> comparator); static String toString(T[] array);  }### Answer:
@Test public void test_sort_Ljava_lang_ObjectIILjava_util_Comparator() { int startIndex = arraySize / 4; int endIndex = 3 * arraySize / 4; BoxedInteger[] originalArray = new BoxedInteger[arraySize]; for (int counter = 0; counter < arraySize; counter++) originalArray[counter] = objectArray[counter]; Arrays.sort(objectArray, startIndex, endIndex, reversedIntegerComparator); for (int counter = 0; counter < startIndex; counter++) assertTrue("Array modified outside of bounds", objectArray[counter] == originalArray[counter]); for (int counter = startIndex; counter < endIndex - 1; counter++) assertTrue("Array not sorted within bounds", reversedIntegerComparator.compare( objectArray[counter], objectArray[counter + 1]) <= 0); for (int counter = endIndex; counter < arraySize; counter++) assertTrue("Array modified outside of bounds", objectArray[counter] == originalArray[counter]); }
@Test public void test_sort_Ljava_lang_ObjectLjava_util_Comparator() { Arrays.sort(objectArray, reversedIntegerComparator); for (int counter = 0; counter < arraySize - 1; counter++) assertTrue("Array not sorted correctly with custom comparator", reversedIntegerComparator.compare(objectArray[counter], objectArray[counter + 1]) <= 0); }
@Test public void test_sort_Ljava_lang_ObjectLjava_util_Comparator_stable() { Element[] array = new Element[11]; array[0] = new Element(122); array[1] = new Element(146); array[2] = new Element(178); array[3] = new Element(208); array[4] = new Element(117); array[5] = new Element(146); array[6] = new Element(173); array[7] = new Element(203); array[8] = new Element(56); array[9] = new Element(208); array[10] = new Element(96); Comparator<Element> comparator = new Comparator<Element>() { public int compare(Element object1, Element object2) { return object1.value - object2.value; } }; Arrays.sort(array, comparator); for (int i = 1; i < array.length; i++) { assertTrue(comparator.compare(array[i - 1], array[i]) <= 0); if (comparator.compare(array[i - 1], array[i]) == 0) { assertTrue(array[i - 1].index < array[i].index); } } }