1(xvi)
Which of the following String methods returns a negative value?
- (a)length()
- (b)equals()
- (c)compareTo()
- (d)charAt()
Show SolutionHide Solution↓
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.