Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
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 (46k 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
0 votes
1 answer
asked Sep 19, 2019 in Java by Anvi (10.2k points)
0 votes
1 answer
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...