Java Program To Check Whether Two Multidimensional Arrays Are Equal
In this tutorial, we will see a Java program to check whether two multidimensional arrays are equal or not.
To check whether two multidimensional arrays are equal or not, we can use the Arrays.deepEquals()
method.
Also see, Java Program To Check Whether Two One-dimensional Arrays Are Equal
Java Program
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import java.util.Arrays;
/**
* Java program to check if the two multidimensional arrays are equal or not
* by Arrays.deepEquals() method
* By coderolls.com
*/
public class MultidimensionalArraysEquals {
public static void main(String[] args) {
int[][] arr = {{3, 4, 5, 7}, {123, 2536, 356}};
int[][] arr2 = {{3, 4, 5, 7}, {123, 2536, 356}};
System.out.println("Comparing arr and arr2 multidimensional arrays: ");
boolean isEqual = Arrays.deepEquals(arr, arr2);
if (isEqual) {
System.out.println("The multidimensional arrays are equal");
} else {
System.out.println("The multidimensional arrays are not equal");
}
}
}
Output
1
2
Comparing arr and arr2 multidimensional arrays:
The multidimensional arrays are equal
Join Newsletter
Get the latest tutorials right in your inbox. We never spam!