KnowledgeBoat Logo
|

Computer Applications

Which of the following String methods returns a negative value?

  1. length()
  2. equals()
  3. compareTo()
  4. charAt()

Java String Handling

2 Likes

Answer

compareTo()

Reason — The compareTo() method compares two strings lexicographically and returns an integer value which can be positive, zero, or negative depending on the comparison. The methods length() returns the length (non-negative), equals() returns a boolean, and charAt() returns a character, so none of them can return a negative value.

Answered By

1 Like


Related Questions