Q:

Java How to print the original index of a sorted 2d array?

suppose I have a 5X1 2D array [2,3,1,4,5], so the index would be 
[[0,0],[1,0],[2,0],[3,0],[4,0]] still, but how to have the original index stay in the value? so then i can print out the index after sorting the value (if that make sense), example
after sorting the value will be [1,2,3,4,5], but the index would be [2,0][0,0][1,0][3,0][4,0] how exactly do you manipulate it?
Thanks in advance, help will be much appreciated!
{
 int[][] array = new int[5][1];

 array = {{2,3,1,4,5}};
 //at this point the array index will be [[0,0],[1,0],[2,0],[3,0],[4,0]]

 Arrays.sort(array);
 //i want the index to stay within the value after sorting...

} 

A:

Odd problem. I'd restructure the code entirely to use my own custom object that held not only the value, but also the original location.
The other way would be to write your own sort, but as you sort, keep a second array that has the original locations, and everything you do to the first array, you mirror on the second array.
A third way: if the values of the array are guaranteed to be unique, you could first duplicate the array. Call one origArray and one sortedArray. Then, when looking at an item in sortedArray, find it in origArray, and that will tell you where it used to be. But this depends on the values being unique, and that's a poor assumption.

