I'm trying to sort a two-dimensional array based on the second column, here is the array:
[1.1, 60.0]
[1.2, 66.66]
[1.3, -1.0]
[1.4, 50.0]
[1.5, 100.0]
[2.1, -1.0]
[2.2, -1.0]
[2.3, -1.0]
I looked into sorting mutli-dimensional arrays and created the following code:
private void sortKnowledgeScores(double[][] knowledgescores){
Arrays.sort(knowledgescores, new Comparator<double[]>() {
@Override
public int compare(double[] o1, double[] o2) {
double itemOne = o1[1];
double itemTwo = o2[1];
// sort on item id
if(itemOne < itemTwo){
return (int) itemOne;
}
return (int) itemIdTwo;
}
This rearranges the array to this:
[2.3, -1.0]
[2.2, -1.0]
[2.1, -1.0]
[1.3, -1.0]
[1.1, 60.0]
[1.2, 66.66]
[1.4, 50.0]
[1.5, 100.0]
Which is correct for the first three values however it puts 50 below 60 and 60.66. How can I adjust my sortKnowledgeScores function to sort my array based on the first column in ascending order?