When comparing arrays in Java, are there any differences between the following 2 statements?
Object[] array1, array2;
array1.equals(array2);
Arrays.equals(array1, array2);
And if so, what are they?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
array1.equals(array2)is the same asarray1 == array2, i.e. is it the same array. As @alf points out it’s not what most people expect.Arrays.equals(array1, array2)compares the contents of the arrays.Similarly
array.toString()may not be very useful and you need to useArrays.toString(array).