Java compareTo() returns?

Java MCQ: compareTo() returns?

a) Positive integer, zero, or negative integer
b) True or false
c) 1 or -1
d) None of the above

Answer:

a) Positive integer, zero, or negative integer

Explanation:

The compareTo() method in Java returns a positive integer, zero, or a negative integer based on whether the object is greater than, equal to, or less than the specified object. It’s commonly used in sorting and searching algorithms.

Reference links:

https://www.rameshfadatare.com/learn-java-programming/
https://www.javaguides.net/p/java-tutorial-learn-java-programming.html

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top