Your question is not very clear and it would help to post an SSCCE. But since getCell returns double, your method should probably look like this:
public int compareTo(Matrix another) {
return Double.valueOf(this.getCell(0, 1))
.compareTo(Double.valueOf(another.getCell(0, 1)));
}
The way this works is to wrap each compared double primitive in a Double object. Since Double implements Comparable<Double>, your method can delegate to Double.compareTo.
Alternatively, you could use the static utility method Double.compare(double, double):
public int compareTo(Matrix another) {
return Double.compare(this.getCell(0, 1), another.getCell(0, 1));
}
This is preferable because it's more concise, but I wanted to mention the first solution because it involves boxing primitives to their object counterparts, which is often necessary in general in order to take advantage of class methods and to use primitives in collections.
getCellreturn? Btw you wrote it wrong the second timegetCel.compareToshould return anintdouble[2]?compareToshould return anint, and that could be causing the problem. But also, yourgetCellmethod should return anInteger(wrapper class) and not anint. Since you haven't posted the error, it's impossible to say. Please post your error message next time.