Sunday, May 1, 2011

equals() method on array

The equals method is not overloaded for arrays which means that:

int[]a = new int[]{1};
int[]b = new int[]{1};
System.out.println(a.equals(b));


Output:
false


As array is not value based, this was bound to happen. Here equals() method Object class that will be called and we know that this version of equals() method checks for the object references and not the values hence false.

No comments:

Post a Comment

Chitika