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
Theequals() 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 witharray2 |
| array2 | Required. The array to be compared witharray1 |
Technical Details
| Returns: | Returnstrue if the arrays are equal.Returns false if the arrays are not equal. |
|---|
Related Pages
❮ Arrays Methods

