Flash cards
Review the key moves
1/4
Core idea
What is the main idea behind Java Arrays. compare() Method?
Lesson checks
Practice each idea before moving on
Short Mimo-style checks built from this lesson's code, terms, and sequence.
1Quick choice
Which statement best captures the main point of this lesson?
2Fill blank
Complete the missing token from the example code.
___[] cars = {"Volvo", "BMW", "Tesla"};3Order
Put the learning moves in the order that makes the concept easiest to apply.
The compare() method compares two arrays lexicographically.
Definition and Usage
Java Arrays. compare() Method
❮ 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. |
|---|