Java - Strings Class-String compareTo() Method - Java

Description

This method compares this String to another Object.

Syntax

Here is the syntax of this method −

Parameters

Here is the detail of parameters −

  • O − the Object to be compared.

Return Value

The value 0 if the argument is a string lexicographically equal to this string; a value less than 0 if the argument is a string lexicographically greater than this string; and a value greater than 0 if the argument is a string lexicographically less than this string.

Example

This will produce the following result −

Output

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Java Topics