Curriculum
Course: Java Basic
Login

Curriculum

Java Basic

Java Home

0/1

Java Introduction

0/1

Java Get Started

0/1

Java Syntax

0/1

Java Comments

0/1

Java Type Casting

0/1

Java Operators

0/1

Java Booleans

0/1

Java Switch

0/1

Java Break / Continue

0/1

Java Errors and Exception

0/1
Text lesson

compare()

 

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));

Definition and Usage

The compare() method assesses two arrays in lexicographical order for comparison.

Syntax

Arrays.compare(array1, array2)

Parameter Values

Parameter

Description

array1

Necessary. Rephrase the array for comparison with array2.

array2

Mandatory. Rephrase the array intended for comparison with array1.

Technical Details

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.