Example
Examine and evaluate two arrays for comparison
String[] cars = {“Volvo”, “BMW”, “Tesla”}; String[] cars2 = {“Volvo”, “BMW”, “Tesla”}; System.out.println(Arrays.compare(cars, cars2)); |
The compare() method assesses two arrays in lexicographical order for comparison.
Arrays.compare(array1,
|
Parameter |
Description |
array1 |
Necessary. Rephrase the array for comparison with array2. |
array2 |
Mandatory. Rephrase the array intended for comparison with array1. |
Returns: |
Returns zero if the arrays are identical. Returns a negative value if array1 precedes array2 lexicographically. Returns a positive value if array1 follows array2 lexicographically. |