Vote count:
0
In an ArrayList I have three double[ ] arrays that I wish to sort on the third array. The third array is also unsorted.
public class LevelList extends ArrayList<double[]> {
My comparator compares doubles:
import java.util.Comparator;
public class Linearize {
static final Comparator<double[]> RATIO_ORDER =
new Comparator<double[]>() {
@Override
public int compare(double[] d1, double[] d2) {
//Sort the ratios based on the fraction column 2
return Double.compare(d1[2], d2[2]);
}
};
}
I then call:
Collections.sort(levelList, Linearize.RATIO_ORDER);
levelList.println();
However, this only results in a sorting of the order of arrays in ArrayList.
In pseudocode, what I wish to achieve is:
For Each Row of ArrayList at Index i
Sort on Array 3
So that this input:
[1.0][2.0][2.1]
[2.0][5.0][2.2]
[1.0][5.0][1.0]
becomes:
[1.0][5.0][1.0]
[1.0][2.0][2.1]
[2.0][5.0][2.2]
because: 2.2 > 2.1 > 1.0
asked 23 secs ago
Sort Three Arrays by ArrayList Index (Row) on a Single Array
Aucun commentaire:
Enregistrer un commentaire