Java Scanner hasNextBoolean() MethodThe hasNextBoolean() is a method of Java Scanner class which is used to check if the next token in this scanner's input can be interpreted as a boolean value using a case insensitive pattern created from the string "true/false". It returns true if the scanner's input can be interpreted as a boolean value, otherwise returns false. SyntaxFollowing is the declaration of hasNextBoolean() method: ParameterThis method does not accept any parameter. ReturnsThe hasNextBoolean() method returns true if and only if this scanner's next token is a valid boolean value. ExceptionsIllegalStateException Compatibility VersionJava 1.5 and above Example 1Output: Result: false Scan String: JavaTpoint.com! Example 2Output: Result: true Scan String: false Example 3Output: Please enter value: true Your entered value: true Example 4Output: false Hello false JavaTpoint! false 13 false + false 13.0 false = false 26 Next TopicJava-scanner-hasnextbyte-method |
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