Returns true if the two specified arrays of ints are equal to one another. 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. Also, two array references are considered equal if both are null.
Line | Description |
---|---|
5 | Declaration and initialization of the array myArray with the values 1, 2, 3, 4 and 5. |
6 | Declaration and initialization of the array mySecondArray with the values 1, 2, 3, 4 and 5. |
8 | The equals() method returns a boolean expression. If two arrays are equal, true is returned. |
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));
}
}
true