Java Boolean compareTo() methodThe 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 1Test it NowOutput: 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 4Test it NowOutput: 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 provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India