Advertisements
Advertisements
Question
Which of the following String methods returns a negative value?
Options
length()equals()compareTo()charAt()
MCQ
Advertisements
Solution
compareTo()
Explanation:
compareTo() returns an int: a negative value if the first string is lexicographically less than the second, zero if they are equal, and a positive value if it is greater. For example, "COMPUTER".compareTo("SCIENCE") yields a negative result because 'C'comes before'S' in character order.
shaalaa.com
Is there an error in this question or solution?
2025-2026 (March) Official Board Paper
