I'm doing a school project and I got my ears caught in a 2d array trying to sort it.
So what I got is this:
String array[][]={ {"5", "22,2", "car payment", "visa", "21/04/2016},
{"3", "15,4", "shop", "cash", "16/02/2017},
{"1", "11,3", "gym", "visa", "10/01/2016} };
What I need to do is list the array by the 2nd column (descending). So my listed array should be something like this:
{"1", "11,3", "gym", "visa", "10/01/2016}
{"3", "15,4", "shop", "cash", "16/02/2017}
{"5", "22,2", "car payment", "visa", "21/04/2016}
I tried something like this:
for (int i = 0; i < array.length; i++){
for (int j = 0; j < array[i].length; j++) {
if (Float.valueOf(array[i][1]) > Float.valueOf(array[i+1][1])) {
temp = array[j+1];
array[j+1] = array[j];
array[j] = temp;
}
}
}
But seems to fail. Where am I doing wrong?
Thank you in advance!