KnowledgeBoat Logo
|
LoginJOIN NOW

Computer Applications

What is the value returned by function compareTo( ), if the invoking string is less than the string compared?

  1. zero
  2. value less than zero
  3. value greater than zero
  4. None of the above

Java String Handling

13 Likes

Answer

value less than zero

Reason — The compareTo() method compares two strings lexicographically, and returns a value based on the following logic:

if string1 > string2 the result will be a positive integer, i.e., result > 0
if string1 < string2 the result will be a negative integer, i.e., result < 0
if string1 = string2 the result will be 0, i.e., result = 0

Answered By

11 Likes


Related Questions