A few more explanations about equals :
The equals method in Object same as == ; that is, he compares the two links to make sure they are equal.
However, equals overridden in the String class, so equals on two lines compares the contents of the strings instead of the links. This is why you need to use equals when comparing String s instead of == . Many other classes in the Java runtime also override equals , so they do something other than comparing references.
Array classes (the class that array objects belong to), however, do not override equals . I think the main reason is that there is no named array array in which the equals override can be displayed. Thus, the idea of ββusing equals to compare content that works for String s does not work for arrays. As a result, for the array x , x.equals(y) will be the same as x == y (if x not null ). It uses the inherited equals from Object .
This is why the Arrays class is provided: to provide you with some of the methods that cannot be provided because there is no class to host them. Arrays.equals and Arrays.toString are two such methods that you would instead of x.equals or x.toString .
source share