Try this code.

char[] firstArray = {'a', 'b', 'c'};
char[] secondArray = {'a', 'b', 'c'};

if (firstArray.length != secondArray.length) {
    System.out.println("False.they are not equal");
} else {
    boolean isEqual = true;
    for (int i = 0; i < firstArray.length; i++) {
        if (firstArray[i] != secondArray[i]) {
            System.out.println("False.they are not equal");
            isEqual = false;
            break;
        }
    }
    if (isEqual)
        System.out.println("true.they are equal");
}
Answer from Naman Gala on Stack Overflow
๐ŸŒ
Liberian Geek
liberiangeek.net โ€บ home โ€บ how-to/tips โ€บ compare two arrays in java
How to Compare Two Arrays in Java?
June 12, 2026 - Next, use the โ€œ==โ€ operator ... other. After that, utilize the โ€œforโ€ loop that iterates the length of an array. Inside it, compare the values of both array elements according to their indexes....
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ java-program-to-check-if-two-arrays-are-equal-or-not
Java Program to Check if two Arrays are Equal or not - GeeksforGeeks
August 19, 2026 - If the lengths are equal, the for loop compares corresponding elements. If any pair of elements is different, the method returns false. If all elements match, the method returns true.
๐ŸŒ
Prutor
prutor.ai โ€บ prutor online academy โ€บ java โ€บ how to compare two arrays in java?
How to compare two arrays in Java?
So when we compare arr1 and arr2, two reference variables are compared, therefore we get the output as โ€œNot Sameโ€ (See this for more examples). How to compare array contents? A simple way is to run a loop and compare elements one by one.
๐ŸŒ
YouTube
youtube.com โ€บ qafox
Java program logic to compare two arrays without using inbuilt methods - YouTube
View Notes Here - http://www.evernote.com/l/AbHxY3qvMHtKWL99_oYpjQLC3bG3CTiLPFE/
Published: November 7, 2020
Views: 2K
๐ŸŒ
How to do in Java
howtodoinjava.com โ€บ home โ€บ java array โ€บ checking if two arrays are equal in java
Checking if Two Arrays are Equal in Java
February 3, 2023 - For example, we do not declare arrays equal if both arrays are null. In this case, we can write our own function where we iterate over the array of items in a for loop and compare the items one by one.
๐ŸŒ
Automationtesting
automationtesting.in โ€บ compare-two-arrays-java-without-built-functions
How to Compare Two Arrays in Java without built-in functions โ€“ Selenium Webdriver Appium Complete Tutorial
November 16, 2019 - In this blog, we will see how to compare two arrays in java without in-built functions. This will be asked in the most of the interview questions. ... Firstly, we compared both the declared arrays length are equal or not using arrayname.length() and returned the value ยท Then, we have iterated a for loop based on array.length() and then compared the arrays index is equal or not and returned the value.
Find elsewhere
๐ŸŒ
W3Schools
w3schools.com โ€บ java โ€บ ref_arrays_compare.asp
Java Arrays compare() Method
Java Examples Java Videos Java ... "Tesla"}; System.out.println(Arrays.compare(cars, cars2)); ... The compare() method compares two arrays lexicographically....
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 33598790 โ€บ traversing-arrays-using-for-loops-in-java
traversing arrays using for loops in java - Stack Overflow
for(int i=0; i<array1.length; i++){ // move along array 1 for(int j=0; j<array2.length; j++){ // moves along array 2 if(array1[i]>array2[j]){ //do something } } }
๐ŸŒ
Medium
medium.com โ€บ @AlexanderObregon โ€บ finding-matching-items-in-two-java-arrays-43751484730f
Finding Matching Items in Two Java Arrays | Medium
July 17, 2025 - The structure is basic, but the behavior is predictable and easy to follow, and for smaller arrays, it holds up just fine. Hereโ€™s the core idea. You take one array and compare every element in it to every element in the second array.
๐ŸŒ
Javatpoint
javatpoint.com โ€บ how-to-compare-two-arrays-in-java
How to Compare Two Arrays in Java - Javatpoint
Java Program to swap two string variables without using third or temp variable.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ compare-two-arrays-java
Compare Two Arrays in Java - GeeksforGeeks
July 23, 2025 - Java provides a direct method Arrays.equals() to compare two arrays.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ java-program-to-compare-two-double-arrays
Java Program to Compare two Double Arrays - GeeksforGeeks
July 23, 2025 - // Java program to compare two double arrays import java.util.*; import java.lang.*; import java.io.*; class GFG { public static void main(String[] args) throws java.lang.Exception { // Two double arrays array1 and array2 double[] array1 = { 1.5, 2.5, 3.5, 4.5 }; double[] array2 = { 1.5, 2.5, 3.5 }; // when the length of two arrays are not // same, then both the arrays cannot be equal // so no need of comparing each element if (array1.length != array2.length) System.out.println("Arrays are not Equal"); else { for (int i = 0; i < array1.length; i++) { // comparing each and every element if (array1[i] != array2[i]) { System.out.println("Arrays are not Equal"); System.exit(0); } } System.out.println("Arrays are Equal"); } } }
๐ŸŒ
Quora
quora.com โ€บ How-do-I-compare-the-elements-of-two-arrays-for-equality-in-Java
How to compare the elements of two arrays for equality in Java - Quora
Answer (1 of 2): It depends on what matters for equality: array size, element order, repeating elements. * Everything counts. [1,2,3] is equal only to other [1,2,3] , but nothing else. Use array equals method * Order does not matter, size can be different, elements can be repeated: [1,2,3] equ...
๐ŸŒ
Just Academy
justacademy.co โ€บ blog-detail โ€บ how-to-compare-two-arrays-in-java
How to Compare Two Arrays in Java by Roshan Chaturvedi | JustAcademy
This is particularly helpful in tasks like searching for specific elements, sorting arrays, or verifying the consistency of data across different arrays. In Java, you can compare arrays using loops, built-in methods like Arrays.equals(), or specialized utilities provided by libraries like Apache Commons ArrayUtils.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ how-to-compare-two-arrays-in-java
How to compare two arrays in Java
How to compare two arrays? Following example uses equals method to check whether two arrays are or not. The above code sample will produce the following result.
๐ŸŒ
DataCamp
datacamp.com โ€บ doc โ€บ java โ€บ compare
Java Array compare()
In Java, comparing arrays involves checking if two arrays are equal in terms of length and content.