Arrays.equals() – check two arrays for equality

This Java code defines a class named ArrayMethods that contains a main method.

The main method creates two arrays, myArray and mySecondArray, and initializes them with the same values: {1, 2, 3, 4, 5}.

Next, the code uses the Arrays.equals method to compare the two arrays and determines if they contain the same elements in the same order. The Arrays.equals method returns a boolean value, true if the arrays are equal, and false if they are not.

Finally, the code outputs the result of the comparison by calling System.out.print with the result of Arrays.equals(myArray, mySecondArray).

import java.util.Arrays;

public class ArrayMethods {
    public static void main(String[] args) {
        int[] myArray = { 1, 2, 3, 4, 5 };
        int[] mySecondArray = { 1, 2, 3, 4, 5 };

        System.out.print(Arrays.equals(myArray, mySecondArray));
    }
}
Output
true