From what I see you just try to see if they are equal, if this is true, just go with something like this:

boolean areEqual = Arrays.equals(arr1, arr2);

This is the standard way of doing it.

Please note that the arrays must be also sorted to be considered equal, from the JavaDoc:

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. In other words, two arrays are equal if they contain the same elements in the same order.

Sorry for missing that.

Answer from comanitza on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › java › compare-two-arrays-java
Compare Two Arrays in Java - GeeksforGeeks
July 23, 2025 - So, when we compare arr1 and arr2, two reference variables are compared, therefore, we get the output as "Not Same". ... Java provides a direct method Arrays.equals() to compare two arrays.
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-arrays-compare-method-with-examples
Java Arrays compare() Method with Examples - GeeksforGeeks
Example of Arrays.compare() method, where we compare two integer arrays with the same elements. Java ·
Published: April 14, 2026
🌐
Baeldung
baeldung.com › home › java › java array › comparing arrays in java
Comparing Arrays in Java | Baeldung
January 8, 2024 - So far we only compared arrays based on their object identities. On the other hand, to check if two arrays are equal in terms of their contents, Java provides the Arrays.equals static method.
🌐
DataCamp
datacamp.com › doc › java › compare
Java Array compare()
While Java does not have a built-in compare() method specifically for arrays, it provides utility methods in the java.util.Arrays class to facilitate array comparison.
🌐
Medium
medium.com › @AlexanderObregon › javas-arrays-equals-method-explained-271f9420177d
Java’s Arrays.equals() Method Explained | Medium
September 11, 2024 - The first thing Arrays.equals() does is check whether the two arrays being compared have the same length. If the arrays don’t match in length, they are immediately considered unequal, and the method returns false.
🌐
Medium
medium.com › @AlexanderObregon › javas-arrays-compare-method-explained-7989daf18608
Java’s Arrays.compare() Method Explained | Medium
February 6, 2025 - The compare() method in the java.util.Arrays class provides a way to compare two arrays lexicographically. This means it determines which array is greater, smaller, or if they are equal by checking the elements in order.
Find elsewhere
🌐
CodeJava
codejava.net › java-core › collections › comparing-arrays-in-java-examples
Comparing Arrays in Java Examples
April 11, 2024 - [Master REST API Development and Java and Spring Boot] Besides sorting, searching, copying and filling, the java.util.Arrays class also provides convenient methods for comparing two arrays and returning hash code an array.
🌐
Oracle
blogs.oracle.com › javamagazine › java-quiz-arrays-compare-mismatch
Quiz yourself: Comparing Java arrays and interpreting the mismatch method | javamagazine
July 10, 2023 - In addition, Arrays.compare checks corresponding pairs of elements at the same positions, starting at index position 0 and checking increasing index positions. As long as pairs of elements compare as equal at the same subscript, it keeps checking.
🌐
Java67
java67.com › 2014 › 05 › how-to-compare-two-arrays-in-java-string-int-example.html
How to compare two Arrays in Java to check if they are equal - [String & Integer Array Example] | Java67
Of course, you can't compare a String array to an int array, which means two arrays are said to be equal if they are of the same type, has the same length, contains the same elements, and in the same order. Now, you can write your own method for checking array equality or take advantage of Java's rich Collection API.
🌐
DEV Community
dev.to › aurban28 › arraysmismatch-and-arrayscompare-in-java-15ch
mismatch() and compare() in Java - DEV Community
November 30, 2024 - When working with arrays in Java, the Arrays class offers several methods to manipulate and compare arrays. Two such methods are mismatch and compare, both of which deal with array comparison but serve different purposes.
🌐
TutorialsPoint
tutorialspoint.com › java › util › arrays_compare_char.htm
Java Arrays compare() Method
As per the result, the comparison is printed. package com.tutorialspoint; import java.util.Arrays; public class ArrayDemo { public static void main(String[] args) { // initialize first char array char array1[] = { 'a', 'b', 'd', 'f', 'p' }; // initialize second char array char array2[] = { 'a', 'b', 'd', 'f', 'p' }; int result = Arrays.compare(array1, array2); if(result > 0) { System.out.println("First array is greater than second array."); } else if (result == 0) { System.out.println("Arrays are same."); } else { System.out.println("First array is less than second array."); } } }
🌐
TutorialsPoint
tutorialspoint.com › javaexamples › array_compare.htm
How to compare two arrays in Java
Following example uses equals method to check whether two arrays are or not. import java.util.Arrays; public class Main { public static void main(String[] args) throws Exception { int[] ary = {1,2,3,4,5,6}; int[] ary1 = {1,2,3,4,5,6}; int[] ary2 = {1,2,3,4}; System.out.println("Is array 1 equal to array 2??
🌐
Medium
medium.com › @codeforhunger › how-to-compare-arrays-in-java-with-examples-93e96ed08ca8
How to Compare Arrays in Java with Examples | by CodeForHunger | Medium
September 3, 2024 - import java.util.Arrays; public class ComparingArrays { public static void main(String[] args) { int arr1[] = {1,2,3,4,5}; int arr2[] = {6,7,8,9,10}; //comparing array contents if(Arrays.equals(arr1,arr2)) System.out.println("Given two arrays are the same"); else System.out.println("Given arrays are not the same"); } }
🌐
TutorialsPoint
tutorialspoint.com › java › util › arrays_equals_int.htm
Java Arrays equals(int[], int[]) Method
Following is the declaration for java.util.Arrays.compare(int[] a, int aFromIndex, int aToIndex, int[] b, int bFromIndex, int bToIndex) method · public static boolean equals(int[] a, int aFromIndex, int aToIndex, int[] b, int bFromIndex, int bToIndex) a − This is the first array to be tested for equality.
🌐
Arraydiff
arraydiff.com › home › tools › array diff › java array compare
Compare Java Arrays & ArrayList — Visual Diff | ArrayDiff
Compare Java arrays, ArrayLists, and collections side by side with color-coded diffs. Paste JSON from Gson/Jackson output — deep recursive comparison at an
🌐
Liberian Geek
liberiangeek.net › home › how-to/tips › compare two arrays in java
Compare Two Arrays in Java - Liberian Geek
June 12, 2026 - However, for a single-level or ... = { {"I", "J", "K"}, {"A", "S", "D"} }; System.out.println("Comparing 1-D Array Using equals() Method => " + Arrays.equals(array1, array2)); System.out.println("Comparing Multi-D Array Using ...