Our task is to compare two arrays in Java and see if they are equal to each other or not. Of-course we can't compare an
String array to an
int array, which means two arrays are said to be equal if they are of same type, has same length, contains same elements and in same order. Now, you can write your own method for checking array equality or take advantage of Java's rich Collection API. Similar to what we have seen while
printing array values in Java,
java.util.Arrays class provides convenient methods for comparing array values. They take care of all four condition, I have mentioned above. In fact,
Arrays class also provide
deepEquals() method to compare two dimensional array in Java. By the way it's not restricted to just two dimensional and also valid for any multi-dimensional array. In this article, we will see examples of c
omparing two String array, two Integer array and two multi dimensional array to learn how to use
equals() and
deepEquals() methods of
java.util.Arrays class. Also
difference between equals() and deepEquals() is a good Java interview question, and asked into of couple of fresher and mid level interviews.