在ArrayList中,我有三个我希望在第三个数组上排序的double []数组。第三个数组也是未排序的。在单个阵列上按ArrayList索引(行)对三个阵列排序
public class LevelList extends ArrayList<double[]> {
我比较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]);
}
};
}
我随后致电:
Collections.sort(levelList, Linearize.RATIO_ORDER);
levelList.println();
然而,这不仅导致在ArrayList的阵列的顺序进行排序。
伪代码,我想实现的是:
For Each Row of ArrayList at Index i
Sort on Array 3
所以此输入:
[1.0][2.0][2.1]
[2.0][5.0][2.2]
[1.0][5.0][1.0]
变为:
[1.0][5.0][1.0]
[1.0][2.0][2.1]
[2.0][5.0][2.2]
因为:2.2> 2.1> 1.0
什么是期望的输出? – Eran 2015-04-03 09:59:22
我已经在上面的“变成:”下展示了它。每个数组应该显示在一列中,按第三列排序。 – noumenal 2015-04-03 10:06:11
我以为那是你已经得到的输出。 – Eran 2015-04-03 10:07:13