❮ Arrays Methods
Example
String[] cars = {"Volvo", "BMW", "Tesla"};
String[] cars2 = {"Volvo", "BMW", "Tesla"};
System.out.println(Arrays.compare(cars, cars2));Definition and Usage
The compare() method compares two arrays lexicographically.
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 0 if the arrays are equal. Returns a negative integer if the array1 is less than array2 lexicographically Returns a positive integer if array1 is greater than array2 lexicographically. |
|---|