I have an array of doubles, in Java : arr1
which I want to sort. Most probably the first option would be the utility method Arrays.sort(double[])
.
The idea is that I want the same changes (e.g. value at index i
is interchanged with value at index j
in arr1
) to be reflected in another array of integers: arr2
(in the sense that the values at the same indexes are changed also in arr2
).
Is there a simple way (a trick) to accomplish this in Java? Or the only way is to implement the sorting algorithm by myself?
UPDATE: I see that people recommend replacing the two arrays with one array of objects containing the 2 values (one from arr1
and one from arr2
). Wouldn't this bring some efficiency penalties. In other words, isn't it less efficient to sort an array of objects than an array of primitive types (doubles in this case) ?
The data is completely static. It's large (it fits in memory) but static.