Arrays deepEquals in java

By | August 23, 2020

Arrays deepEquals in java:

It returns true if the two specified arrays are deeply equal to one another. Unlike the equals(Object[],Object[]) method, this method is appropriate for use with nested arrays of arbitrary depth.Two array references are considered deeply equal if both are null, or if they refer to arrays that contain the same number of elements and all corresponding pairs of elements in the two arrays are deeply equal.

Two possibly null elements e1 and e2 are deeply equal if any of the following conditions hold:

  • e1 and e2 are both arrays of object reference types, and Arrays.deepEquals(e1, e2) would return true
  • e1 and e2 are arrays of the same primitive type, and the appropriate overloading of Arrays.equals(e1, e2) would return true.
  • e1 == e2
  • e1.equals(e2) would return true.

Note that this definition permits null elements at any depth.If either of the specified arrays contain themselves as elements either directly or indirectly through one or more levels of arrays, the behavior of this method is undefined.

a1 – one array to be tested for equality
a2 – the other array to be tested for equality
true if the two arrays are equal


Compare with Arrays.equals() method:


Recommended Posts:

Java map examples

Find the third largest number in an array in Java

Star pattern programs in Java

* This article has been contributed by Suneel Kumar Gudupu. If you want to contribute any articles, please send at

Tags: arrays deepequals in java

Leave a Reply

Your email address will not be published. Required fields are marked *