Java Arrays.equals() Method
Example
Find out if two arrays are equal:
String[] cars = {"Volvo", "BMW", "Tesla"};
String[] cars2 = {"Volvo", "BMW", "Tesla"};
System.out.println(Arrays.equals(cars, cars2));
Definition and Usage
The equals()
method checks whether two
arrays are equal.
Note: Two arrays are consided equal if they share the same elements in the same order.
Syntax
Arrays.compare(array1, array2)
Parameter Values
Parameter | Description |
---|---|
array1 | Required. The array to compare with array2 |
array2 | Required. The array to be compared with array1 |
Technical Details
Returns: | Returns true if the arrays are equal.Returns false if the arrays are not equal. |
---|
Related Pages
❮ Arrays Methods