0 votes
1 view
in Java by (10.2k points)

When comparing arrays in Java, are there any differences between the following 2 statements?

array1.equals(array2);

Arrays.equals(array1, array2);

And if so, what are they?

1 Answer

0 votes
by (46.1k points)
array1.equals(array2) is the equivalent as array1 == array2, i.e. is it the same array. it's not what most utmost people expect.

Arrays.equals(array1, array2) connects the contents of the arrays.

Similarly, array.toString() may not be quite useful and you need to use Arrays.toString(array).

Related questions

0 votes
1 answer
asked Sep 19, 2019 in Java by Anvi (10.2k points)
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Aug 29, 2019 in Java by Nigam (4.1k points)
+1 vote
2 answers
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...