我在对动态双向数组进行排序时遇到了一些麻烦。我搜索并找到了这个解决方案:
Double[][] sortedOutput = new Double[length][4];
//...
// processing and filling my tab like that
sortedOutput[k][0] = content[i].getLeftSpeed);
sortedOutput[k][1] = content[i].getRightSpeed();
sortedOutput[k][2] = content[i].getNormAvgPowOutput();
// ...
// Now i'm trying to sort the tab
Arrays.sort(sortedOutput, new java.util.Comparator<double[]>()
{
public int compare(double[]a, double[]b)
{
return Double.compare(a[0], b[0]);
}
});
但不知何故我不工作:
The method sort(T[], Comparator<? super T>) in the type Arrays is not applicable for the arguments (Double[][], new Comparator<double[]>(){})
为什么我不能使用Arrays.sort
with double
?
我也尝试过上课:
package IOControl;
import java.util.Comparator;
public class CompareDoubleArray implements Comparator<double[]>
{
private int column;
public CompareDoubleArray(int column)
{
this.column = column;
}
public int compare(double[] arg0, double[] arg1)
{
return Double.valueOf(arg0[column]).compareTo(Double.valueOf(arg1[column]));
}
}
我应该如何使用我的课程?我做错什么了?任何帮助都会很好,谢谢:)