Android Utililty Methods Array Sort

List of utility methods to do Array Sort

Description

The list of methods to do Array Sort are organized into topic(s).

Method

voidsortTwoArrays( A[] firstArray, B[] secondArray)
Utility method to sort two related arrays - that is, two arrays where the elements are related to each other by their position in the array.
if (firstArray.length != secondArray.length) {
    throw new RuntimeException(
            "Both arrays must be of the same length");
class element {
    public A first;
    public B second;
element[] elements = new element[firstArray.length];
Arrays.sort(elements, new Comparator<element>() {
    public int compare(element a, element b) {
        return a.first.compareTo(b.first);
});
for (int i = 0; i < elements.length; i++) {
    firstArray[i] = elements[i].first;
    secondArray[i] = elements[i].second;