KnowledgeBoat Logo

Computer Applications

Describe the purpose and write the syntax of compareTo() function.

Java String Handling

ICSE 2010

18 Likes

Answer

It compares two strings lexicographically. It results in the difference of the ASCII codes of the corresponding characters. Its return type is int.

Syntax:


int <variable-name> = <string-variable>.compareTo(<string-variable2>);

Answered By

10 Likes


Related Questions