Table of Content

Check if two Object Arrays are equal or not in Java


Declaration :

Explanation :

Purpose The java.util.Arrays.equals(Object[] a Object[] a2) method returns true if the two specified arrays of objects are equal to one another.The two arrays are considered equal if both arrays contain the same number of elements and all corresponding pairs of elements in the two arrays are equal.Two objects e1 and e2 are considered equal if (e1==null ? e2==null : e1.equals(e2)).The two arrays are equal if they contain the same elements in the same order.Two array references are considered equal if both are null.
Parameters a ===> This is the array to be tested for equality.
a2 ===> This is the other array to be tested for equality.
Return Value This method returns true if the two arrays are equal else false.
Exception NA

Java Program : Example

Below example will explain java.util.Arrays.equals() method.

Output of Program :