By adding @Henry to the answer, before comparing the lengths of two given arrays, you must make sure that none of them is null , so that you do not get a NullPointerException .
You can also compare array references before iterating over their elements.
Something like that:
public static boolean equalArrays(double[] x, double[] y) { if (x == null || y == null || x.length != y.length) { //NOTE: That if both x and y are null we return false despite the fact that you could argue that they are equal return false; } if (x == y) { return true; } for (int index = 0; index < x.length; index++) { if (x[index] != y[index]) { return false; } } return true; }
Tmr source share