Java Boolean compareTo() method20 Mar 2025 | 2 min read The compareTo() method of Java Boolean class compares the Boolean instance with the Boolean argument and returns an integer value based on the result of this method. Syntax:Parameters:Here, b is the Boolean instance passed (which is compared). Return Value:This method returns an integer value.
Example 1ExampleCompile and RunOutput: Both values are equal Example 2Output: Enter two no.s I no : 89 II no : 90 90 is greater Example 3Output: Enter your age : 16 Sorry! you can vote after 2.0 years. Example 4ExampleCompile and RunOutput: Error:(13, 19) java: boolean cannot be dereferenced The Boolean is a primitive data type. Its object can't be used to call the Boolean class methods. If done, so it will give the above error. Next TopicJava Boolean |
We request you to subscribe our newsletter for upcoming updates.

We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India